Using OpenWeatherMap API gives 401 error

孤人 提交于 2019-12-13 13:48:00

问题


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:


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=...


来源:https://stackoverflow.com/questions/33091948/using-openweathermap-api-gives-401-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!