gpt4 book ai didi

python - 使用 OpenWeatherMap API 会出现 401 错误

转载 作者:太空狗 更新时间:2023-10-30 01:53:57 29 4
gpt4 key购买 nike

我正在尝试获取 JSON 格式的伦敦天气数据,但我收到了 HTTPError: HTTP Error 401: Unauthorized。如何让 API 正常工作?

import urllib2
url = "http://api.openweathermap.org/data/2.5/forecast/daily?q=London&cnt=10&mode=json&units=metric"
response = urllib2.urlopen(url).read()

最佳答案

docs通过告诉您需要先注册 API key 来打开。

To access the API you need to sign up for an API key

由于您的网址不包含 key ,该网站会告诉您您未获得授权。按照说明获取 key ,然后将其添加到查询参数中。

http://api.openweathermap.org/data/2.5/forecast/daily?APPID=12345&q=...

关于python - 使用 OpenWeatherMap API 会出现 401 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33091948/

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