After entering the wrong name in Botou the weather on pythone, I get an error,what to do with it?

After entering the incorrect city name, the bot stops working, what to do with it? I would be very grateful for the help

import pyowm
import telebot

owm = pyowm.OWM('***********', language = "EN")
bot = telebot.TeleBot("***************")

@bot.message_handler(content_types=['text'])
def send_echo(message):
observation = owm.weather_at_place( message.text )
w = observation.get_weather()
temp = w.get_temperature('celsius')["temp"]
hum = w.get_humidity()
time = w.get_reference_time(timeformat='iso')
wind = w.get_wind()["speed"]

answer ="In" + message.text + " now " + w.get_detailed_status() + "\n"
answer += "the Temperature is now in district" + str(temp) + "\n\n" + "\skorosti the wind: "+ str(wind) + "m/s" + "\n" + "\plainest: "+ str(hum) + "%" + "\n" + "\purema: "+ str(time) + "\n"

if temp < 11:
answer += "it is very cold."
elif temp < 20:
answer += "is Now cool, it is better to dress warmly."
else:
answer += "the Temperature is normal!"

bot.send_message(message.chat.id, answer)
bot.polling( none_stop = True)
input()

After entering the wrong names popping up this error: raise api_response_error.NotFoundError('Unable to find the resource')
pyowm.exceptions.api_response_error.NotFoundError: The amazing item was not found.
Reason: Unable to find the resource
April 7th 20 at 15:19
1 answer
April 7th 20 at 15:21
Solution
To use the try - except.
Working code:
import telebot
import pyowm

owm = pyowm.OWM('key', language = "EN")
bot = telebot.TeleBot('token')

@bot.message_handler(content_types=['text'])
def send_echo(message):
try:
 observation = owm.weather_at_place( message.text )
 w = observation.get_weather()
 temp = w.get_temperature('celsius')["temp"]
 hum = w.get_humidity()
 time = w.get_reference_time(timeformat='iso')
 wind = w.get_wind()["speed"]

 answer ="In" + message.text + " now " + w.get_detailed_status() + "\n"
 answer += "the Temperature is now in district" + str(temp) + "\n\n" + "\skorosti the wind: "+ str(wind) + "m/s" + "\n" + "\plainest: "+ str(hum) + "%" + "\n" + "\purema: "+ str(time) + "\n"

 if temp < 11:
 answer += "it is very cold."
 elif temp < 20:
 answer += "is Now cool, it is better to dress warmly."
else:
 answer += "the Temperature is normal!"

 bot.send_message(message.chat.id, answer)
except:
 bot.send_message(message.chat.id,'Error! The city is not found.')
bot.polling( none_stop = True)
input()

5e494983ac97a904403016.png

Find more questions by tags Python