我正在尝试从城镇获取天气信息,并从该列表中打印出2个项目。但是,当我尝试运行代码时,我收到此错误:
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"))
// EDIT
我刚刚重新启动了我的程序,它只是抛出了一个&#34; TypeError:&#39; str&#39;对象不可调用&#34;而是错误。
错误讯息:
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
有关做什么的任何线索?
答案 0 :(得分:0)
您正试图致电string.lowercase(blabla)
以及您获得TypeError
你应该做
print "In Boston, Lincolnshire it is currently: " + bostonweather['current_conditions']['text'].lower() + " and " + bostonweather['current_conditions']['temperature'].lower() + ("C.\n")
答案 1 :(得分:0)
在打印之前尝试制作所有字符串
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())