Как исправить ошибку pyowm.commons.exceptions.NotFoundError: Unable to find the resource или как пользоваться try

import pyowm # module for weather

from pyowm import OWM # I don't know (need to work module)
from pyowm.utils.config import get_default_config #special for ru language

config_dict = get_default_config()# special for ru language
config_dict['language'] = 'en'# special for different languages

owm = OWM('API') # is my API-key from openweathermap.org
mgr = owm.weather_manager()

city = input('Enter your city name: ')

observation = mgr.weather_at_place(city) # I don't know (need to work module)
try:
    w = observation.weather # variable with weather
except pyowm.commons.exceptions.NotFoundError: Unable to find the resource:
    print("I don't know such a city")

w_detailed_status = w.detailed_status # clouds

w_wind_speed = w.wind()['speed'] # wind speed
w_wind_deg = w.wind()['deg'] # wind degree
if w_wind_deg == 0:
    w_wind_deg = 'N (North)'
elif w_wind_deg <= 45:
    w_wind_deg = 'NE (North-East)'
elif w_wind_deg <= 90:
    w_wind_deg = 'E (East)'
elif w_wind_deg <= 135:
    w_wind_deg = 'SE (South-East)'
elif w_wind_deg <= 180:
    w_wind_deg = 'S (South)'
elif w_wind_deg <= 225:
    w_wind_deg = 'SW (South-West)'
elif w_wind_deg <= 270:
    w_wind_deg = 'W (West)'
elif w_wind_deg <= 315:
    w_wind_deg = 'NW (North-West)'
elif w_wind_deg <= 360:
    w_wind_deg = 'N (North)'

w_humidity = w.humidity # humidity

w_max_temp = w.temperature('celsius')['temp_max'] # max temp
w_min_temp = w.temperature('celsius')['temp_min'] # min temp
w_temp = w.temperature('celsius')['temp'] # now temp

w_clouds = w.clouds

print('status: '+ w_detailed_status)
print('wind speed: '+ str(w_wind_speed))
print('wind degree: '+ str(w_wind_deg))
print('humidity: '+ str(w_humidity))
print('max temp: '+ str(w_max_temp))
print('min temp: '+ str(w_min_temp))
print('now temp: '+ str(w_temp))
print('clouds: '+ str(w_clouds))


input()

Пытаюсь понять как не допускать ошибки при неправильном городе посмотрел документацию pyowm, но понятней не стало. А может быть сам try стоит не там. Если не сложно, помогите. Спасибо


Ответы (0 шт):