The retrieval of JSON data in python is not successful.I want your help.

Asked 2 years ago, Updated 2 years ago, 122 views

I'm studying a program to get weather forecasts from openweathermap on python.However, a 401 error occurred and we cannot proceed.I saw on the Internet that 401 errors are not allowed, but I have logged in to the site.

I don't understand why I'm logged in but I'm not allowed, but if anyone knows why I get an "unauthorized" error, could you please answer me?

import json, requests, print
APPID='-'# API Key Definitions
url='http://api.openweathermap.org/data/2.5/forecast/daily?q={}&cnt=3&appid={}.format('Akashi-shi,jp',APPID)
response=requests.get(url)
response.raise_for_status()

weather_data=json.loads(response.text)
print.pprint(weather_data)

Resolved. [URL misrepresentation]
There was a difference between the contents of the book and the official documentation.From now on, I will definitely check the official documents.

#×→url='http://api.openweathermap.org/data/2.5/forecast/daily?q={}&cnt=3&appid={}'.format('London', APPID)
url='http://api.openweathermap.org/data/2.5/weather?q={}&appid={}'.format('London', APPID)

python json

2022-09-30 20:24

1 Answers

According to the error message, a valid APPID is not configured.I'm not familiar with this service, but I think I need to follow the instructions on the link below to create an account and get an APPID.

http://openweathermap.org/faq


2022-09-30 20:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.