您好,我尝试按照此manual进行python开放天气api
这是示例操作代码:
import openweather
from datetime import datetime
# create client
ow = openweather.OpenWeather()
# find weather stations near me
stations = ow.find_stations_near(
7.0, # longitude
50.0, # latitude
100 # kilometer radius
)
# iterate results
for station in stations:
print station
但这不起作用,我会收到以下错误消息:
OpenWeather.do_request(): No connection. (1. attempt)
OpenWeather.do_request(): No connection. (2. attempt)
OpenWeather.do_request(): No connection. (3. attempt)
知道为什么吗?
最佳答案
您需要将有效的API密钥附加到“创建客户端”请求。该软件包的作用是将您的输入解析为JSON请求并返回,因此在创建客户端时需要具有API密钥,以便将其附加到发送给openweathermap的URL上。
import openweather
from datetime import datetime
# create client
ow = openweather.OpenWeather('3f14d26ebe5502a831e98067ae851b99')
# find weather stations near me
stations = ow.find_stations_near(
7.0, # longitude
50.0, # latitude
100 # kilometer radius
)
# iterate results
for station in stations:
print station
关于python - python openweather包不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50007658/