gpt4 book ai didi

python openweather 包不起作用

转载 作者:行者123 更新时间:2023-12-01 09:30:32 24 4
gpt4 key购买 nike

你好,我尝试遵循这个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 key 附加到“创建客户端”请求。这个包的作用是将您的输入解析为 JSON 请求并返回,因此当您创建客户端时它需要具有 API key ,以便将其附加到发送到 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 openweather 包不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50007658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com