python - python openweather包不起作用
问题描述
你好我尝试按照本手册获取python open weather 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
推荐阅读
- html - 为什么 :checked 不适用于我的单选按钮?
- php - 允许在 WooCommerce 5+ 中重新发送新订单通知
- java - 如何在启动器活动之前执行异步任务,如启动
- sql - Oracle SQL:当表中的记录存在时显示最大值
- laravel - React-Native 图像未通过 Content URI(react-native-camera)使用 Axios(MultiPart 表单数据)上传
- flutter - 我应该在哪里设置我的 Flutter 桌面应用程序的固定大小?
- php - Laravel 在 null 错误上调用成员函数 getName()
- angular - 覆盖 Angular 预定义的日期格式
- jenkins - 使用 Jenkins 脚本 (Groovy),我们可以为所有现有的 FreeStyle 项目自动化“添加构建步骤”吗?
- javascript - 是否存在与 CryptoJS 中 Jasypt-Library 的 AES256TextEncryptor 类等效的行为?