我试图从一个城镇获取天气信息,并从该列表中打印出2个项目。然而,当我尝试运行代码,我得到这个错误:AtrributeError:'NoneType'对象没有属性'data'&TypeError:'str'对象不可调用
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'
这是我的代码:
import pywapi
import string
bostonweather = pywapi.get_weather_from_weather_com('UKXX1701', 'metric')
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'对象不可调用”的错误。
错误消息:
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
做什么任何线索?
这仍然给我一个Typeerror:不支持的操作数兰德类型的+:'NoneType'和'str'' :( 编辑:没关系!我从你的代码中删除了一些括号,并且它工作:)谢谢! – davidpox 2014-11-22 16:39:51
不知道为什么它会给你错误,我用python3.4检查过,它很好。我想你的翻译有不同的版本,但无论如何,我很高兴你修复它:) – 2014-11-23 22:06:29