我正在尝试获取瑞典的历史天气数据(今年)。
为此,我偶然发现了免费的API源代码:https://rapidapi.com/visual-crossing-corporation-visual-crossing-corporation-default/api/visual-crossing-weather/
但是,在使用所提供的代码和示例时,我得到了错误:
{"message":"Invalid API key. Go to https:\/\/docs.rapidapi.com\/docs\/keys for more info."}
输入中似乎没有任何API密钥...
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,我收到了一个学生密钥,但是在他们的示例代码中,没有关于如何使用坐标以及在哪里实现该密钥的说明。它看起来与他们网站上的文档不同。
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/
我的最终目标是将其应用于包含时间戳、纬度和经度值的我自己的数据,如下所示:
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的历史天气数据)和位置(瑞典)获取天气信息。
发布于 2021-10-13 11:09:42
您只需要在headers
中添加x-rapidapi-key
如果您想使用RapidAPI集线器上可用的任何API,x-rapidapi-key
实际上是RapidAPI为您提供的一个API。有趣的是,您可以使用这个API密钥访问超过35,000个API。
您可以在Developer Dashboard上的应用程序的安全页面中找到API密钥。
https://stackoverflow.com/questions/68595663
复制相似问题