0

这是我的问题我正在尝试编写一个脚本来获取我所在位置的天气这是代码

import requests
url = ("http://api.worldweatheronline.com/free/v1/weather.ashx?key=hfvb4qmehh8g9p8krcbmj8ew&q=48.85,2.35&fx=no&format=json") 

r = requests.get(url)
forecast = r.json
print (forecast)["data"]["current_condition"]["temp_F"] 

这是错误

<bound method Response.json of <Response [200]>>
Traceback (most recent call last):
  File "C:\Users\Grant\Desktop\weather.py", line 6, in <module>
    print (forecast) ["data"]["current_condition"]["temp_F"]
TypeError: 'NoneType' object is not subscriptable

任何帮助,将不胜感激

4

1 回答 1

4
print (forecast) ["data"]["current_condition"]["temp_F"] 

索引print()调用的结果。这可能不是你想要的。

尝试

print(forecast["data"]["current_condition"]["temp_F"])

反而。

于 2013-06-25T17:42:33.493 回答