+ 1

I don't know why I always get an error

import urllib.request,json city=input() k='https://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid=af50bbd7309f973b6a2318253e78ad20'.format(city); api=urllib.request.urlopen(k) api_data=api.read() api_data_info=api_data.decode() a=json.loads(api_data_info) des=a['weather'][0]['description'] temp=a['main']['temp'] temp_min=a['main']['temp_min'] temp_max=a['main']['temp_max'] humidity=a['main']['humidity'] sun_rise=a['sys']['sunrise'] sun_set=a['sys']['sunset'] print('Weather Report of : {}'.format(city).center(40)) print('\n---------------------') print('---------------------\n') print('Description : {}'.format(des)) print('Temperature : {}'.format(temp)) print(f'Minimum temperature : {temp_min}°C') print(f'Maximum temperature : {temp_max}°C') print(f'Humidity : {humidity}°C') print(f'Sun Rise : {sun_rise}') print(f'Sun Set : {sun_set}') print('\n-------------------') print('Thanks for having a look at this code') print('-------------------\n')

28th Sep 2020, 8:04 AM
Ibrahim Phenom
2 Respostas
+ 2
I get error 401. Looks like its an invalid api key
28th Sep 2020, 8:28 AM
Slick
Slick - avatar
+ 1
Tag Python rather than just 'g' ☝ Proper tags improve context clarity and search-ability 👍
28th Sep 2020, 8:56 AM
Ipang