Python ATRIBUTEERROR:&x27;非类型';对象没有属性';数据'&;类型错误:';str';对象不可调用
我试图从一个城镇获取天气信息,并从列表中打印出两项。但是,当我尝试运行代码时,出现以下错误:Python ATRIBUTEERROR:&x27;非类型';对象没有属性';数据'&;类型错误:';str';对象不可调用,python,raspberry-pi,python-idle,Python,Raspberry Pi,Python Idle,我试图从一个城镇获取天气信息,并从列表中打印出两项。但是,当我尝试运行代码时,出现以下错误: Traceback (most recent call last): File "/home/pi/Desktop/python/PyWeather.py" line 4, in <module> bostonweather = pywapi.get_weather_from_weather_com('UKXX1701', units = 'metric')
Traceback (most recent call last):
File "/home/pi/Desktop/python/PyWeather.py" line 4, in <module>
bostonweather = pywapi.get_weather_from_weather_com('UKXX1701', units = 'metric')
File "/home/pi/Desktop/python/pywapi.py" line 239, in get_weather_from_weather_com
'wind')[0].getElementsByTagName(tag2)[0].firstChild.data
AtrributeError: 'NoneType' object has no attribute 'data'
//编辑
我刚刚重新运行了我的程序,它只是抛出了一个“TypeError:“str”对象不可调用”错误
错误消息:
Traceback (most recent call last):
File "/home/pi/Desktop/python/PyWeather.py" line 5, in <module>
print ("In Boston, Lincolnshire it is currently: ") + string.ascii_lowercase(bostonweather['current_conditions']['text'] + (" and ") + string.ascii_lowercase(bostonweather['current_conditions']['temperature'] + ("C.\n"))
TypeError: 'str' object is not callable
回溯(最近一次呼叫最后一次):
文件“/home/pi/Desktop/python/PyWeather.py”第5行,在
打印(“在林肯郡波士顿,它目前是:”)+string.ascii_小写(bostonweather['current_conditions']['text']+(“and”)+string.ascii_小写(bostonweather['current_conditions']['temperature']+(“C.\n”))
TypeError:“str”对象不可调用
有什么线索吗?您正在尝试调用
string.lowercase(blabla)
,这就是您得到TypeError
你应该这样做
print "In Boston, Lincolnshire it is currently: " + bostonweather['current_conditions']['text'].lower() + " and " + bostonweather['current_conditions']['temperature'].lower() + ("C.\n")
打印之前,请尝试生成所有字符串
import pywapi
bostonweather = pywapi.get_weather_from_weather_com('UKXX1701', 'metric')
print ("In Boston, Lincolnshire it is currently: " + str(bostonweather['current_conditions']['text']).lower() + " and " + str(bostonweather['current_conditions']['temperature']).lower())
我尝试了这个方法,但现在我得到了这个错误:
Typeerror:不支持+:'NoneType'和'str'的操作数类型
这仍然给了我一个Typeerror:不支持+:'NoneType'和'str'的操作数类型
:(编辑:无需考虑!我从字符串中删除了一些括号,就像在您的代码中一样,它起了作用:)谢谢!不知道为什么它会给你错误,我用python3.4检查了一下,很好。我想你的解释器有不同的版本,但不管怎样,我很高兴你修复了它:)
import pywapi
bostonweather = pywapi.get_weather_from_weather_com('UKXX1701', 'metric')
print ("In Boston, Lincolnshire it is currently: " + str(bostonweather['current_conditions']['text']).lower() + " and " + str(bostonweather['current_conditions']['temperature']).lower())