首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Python:向公共API请求批量历史天气数据

Python:向公共API请求批量历史天气数据
EN

Stack Overflow用户
提问于 2021-07-30 18:31:40
回答 1查看 264关注 0票数 0

我正在尝试获取瑞典的历史天气数据(今年)。

为此,我偶然发现了免费的API源代码:https://rapidapi.com/visual-crossing-corporation-visual-crossing-corporation-default/api/visual-crossing-weather/

但是,在使用所提供的代码和示例时,我得到了错误:

代码语言:javascript
运行
复制
{"message":"Invalid API key. Go to https:\/\/docs.rapidapi.com\/docs\/keys for more info."}

输入中似乎没有任何API密钥...

代码语言:javascript
运行
复制
url = "https://visual-crossing-weather.p.rapidapi.com/history"

querystring = {"startDateTime":"2019-01-01T00:00:00",
               "aggregateHours":"24",
               "location":"Washington,DC,USA",
               "endDateTime":"2019-01-03T00:00:00",
               "unitGroup":"us",
               "dayStartTime":"8:00:00",
               "contentType":"csv",
               "dayEndTime":"17:00:00",
               "shortColumnNames":"0"}

headers = {'x-rapidapi-host': 'visual-crossing-weather.p.rapidapi.com'}

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

找不到该页面链接(错误404)。

我假设不需要密钥,因为它应该是一个公共来源。

我还遇到了: OpenWeatherMap,我收到了一个学生密钥,但是在他们的示例代码中,没有关于如何使用坐标以及在哪里实现该密钥的说明。它看起来与他们网站上的文档不同。

代码语言:javascript
运行
复制
import requests

url = "https://community-open-weather-map.p.rapidapi.com/climate/month"

querystring = {"q":"San Francisco"}

headers = {'x-rapidapi-host': 'community-open-weather-map.p.rapidapi.com'}

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

来源:https://rapidapi.com/community/api/open-weather-map/

我的最终目标是将其应用于包含时间戳、纬度和经度值的我自己的数据,如下所示:

代码语言:javascript
运行
复制
timestamp   latitude    longitude
0   2021-06-09 08:12:33.820 57.728905   11.949309
1   2021-06-09 08:15:36.370 57.728874   11.949407
2   2021-06-09 08:16:06.000 57.728916   11.949470
3   2021-06-09 08:16:52.190 57.728836   11.949342
4   2021-06-09 08:18:08.000 57.728848   11.949178

我怎样才能让这个公共API工作呢?或者,我可以使用(以及如何请求)从我的时间戳(20202的历史天气数据)和位置(瑞典)获取天气信息。

EN

回答 1

Stack Overflow用户

发布于 2021-10-13 11:09:42

您只需要在headers中添加x-rapidapi-key

如果您想使用RapidAPI集线器上可用的任何API,x-rapidapi-key实际上是RapidAPI为您提供的一个API。有趣的是,您可以使用这个API密钥访问超过35,000个API。

您可以在Developer Dashboard上的应用程序的安全页面中找到API密钥。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68595663

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档