Using OpenWeatherMap API gives 401 error

2019-06-25 02:58发布

I'm trying to get the weather data for London in JSON but I am getting HTTPError: HTTP Error 401: Unauthorized. How do I get the API working?

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()

1条回答
我只想做你的唯一
2楼-- · 2019-06-25 03:33

The docs open by telling you that you need to register for an API key first.

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

Since your url doesn't contain a key, the site tells you you're not authorized. Follow the instructions to get a key, then add it to the query parameters.

http://api.openweathermap.org/data/2.5/forecast/daily?APPID=12345&q=...
查看更多
登录 后发表回答