Python OpenWeather软件包不起作用



你好,我尝试按照本手册进行python开放天气api

在这里示例manula代码:

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

相关内容

最新更新