【发布时间】:2021-10-06 06:38:09
【问题描述】:
我正在尝试获取瑞典的历史天气数据(从今年开始)。
为此,我偶然发现了免费的 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 年的历史天气数据)和位置(瑞典)获取天气信息。
【问题讨论】:
-
您需要一个 API 密钥才能以
authorization的形式请求此 API 密钥。 -
我是一名学生,因此收到了一份用于 OpenWeatherMap 的信息……但它是在哪里实施的呢?我想我只能访问 5 天前的历史天气数据……我的观察时间是在 5 月至 7 月。我认为这是我唯一可以用于我的目的:openweathermap.org/history
标签: python json request openweathermap weather-api