Пытался соединить два кода: PyOwm и TeleBot, но бот выключается и выдаёт ошибку

Пытался соединить два кода: PyOwm и TeleBot, но бот выключается и выдаёт ошибку Вот код:

from pyowm import OWM
from pyowm.utils import config as cfg
import telebot


config = cfg.get_default_config()
config['language'] = 'ru'

owm = OWM('[token]', config)
bot = telebot.TeleBot("[token]")

@bot.message_handler(content_types=['text'])
def send_echo(message):
    mgr = owm.weather_manager()
    observation = mgr.weather_at_place( message.text )
    w = observation.weather
    temp = w.temperature('celsius') ["temp"]

    answer = "В городе " + message.text + " сейчас " + w.detailed_status + "\n"
    answer += "Температура там около " + str(temp) + "\n\n"

    if temp < 1:
        answer += "Сейчас очень холодно что пздц. Оденься как к походу На Северный полюс, иначе бубеньчики отморозишь!!!"
    elif temp < 10:
        answer += "Надень джинсы, да лёгкую куртку, а то на улице немного холодно"
    elif temp < 20:
        answer += "Сейчас на улице тепло, но лучше надень свитшот и джинсы"
    else:
        answer += "На улице жарко, что хоть в голым на улицу выходи"

    bot.send_message(message.chat.id, answer)

bot.polling( none_stop = True )

На выходе получил это:

2020-08-16 17:08:33,914 (util.py:68 WorkerThread2) ERROR - TeleBot: "NotFoundError occurred, args=('Unable to find the resource',)
Traceback (most recent call last):
  File "C:\Users\Никита Картавый\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\util.py", line 62, in run
    task(*args, **kwargs)
  File "Telega.py", line 15, in send_echo
    observation = mgr.weather_at_place( message.text )
  File "C:\Users\Никита Картавый\AppData\Local\Programs\Python\Python38\lib\site-packages\pyowm\weatherapi25\weather_manager.py", line 53, in weather_at_place
    _, json_data = self.http_client.get_json(OBSERVATION_URI, params=params)
  File "C:\Users\Никита Картавый\AppData\Local\Programs\Python\Python38\lib\site-packages\pyowm\commons\http_client.py", line 143, in get_json
    HttpClient.check_status_code(resp.status_code, resp.text)
  File "C:\Users\Никита Картавый\AppData\Local\Programs\Python\Python38\lib\site-packages\pyowm\commons\http_client.py", line 288, in check_status_code
    raise exceptions.NotFoundError('Unable to find the resource')
pyowm.commons.exceptions.NotFoundError: Unable to find the resource
"
Traceback (most recent call last):
  File "Telega.py", line 33, in <module>
    bot.polling( none_stop = True )
  File "C:\Users\Никита Картавый\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\__init__.py", line 427, in polling
    self.__threaded_polling(none_stop, interval, timeout)
  File "C:\Users\Никита Картавый\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\__init__.py", line 451, in __threaded_polling
    self.worker_pool.raise_exceptions()
  File "C:\Users\Никита Картавый\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\util.py", line 111, in raise_exceptions
    six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
  File "C:\Users\Никита Картавый\AppData\Local\Programs\Python\Python38\lib\site-packages\six.py", line 703, in reraise
    raise value
  File "C:\Users\Никита Картавый\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\util.py", line 62, in run
    task(*args, **kwargs)
  File "Telega.py", line 15, in send_echo
    observation = mgr.weather_at_place( message.text )
  File "C:\Users\Никита Картавый\AppData\Local\Programs\Python\Python38\lib\site-packages\pyowm\weatherapi25\weather_manager.py", line 53, in weather_at_place
    _, json_data = self.http_client.get_json(OBSERVATION_URI, params=params)
  File "C:\Users\Никита Картавый\AppData\Local\Programs\Python\Python38\lib\site-packages\pyowm\commons\http_client.py", line 143, in get_json
    HttpClient.check_status_code(resp.status_code, resp.text)
  File "C:\Users\Никита Картавый\AppData\Local\Programs\Python\Python38\lib\site-packages\pyowm\commons\http_client.py", line 288, in check_status_code
    raise exceptions.NotFoundError('Unable to find the resource')
pyowm.commons.exceptions.NotFoundError: Unable to find the resource

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

Автор решения: Elusha

Судя по всему ошибка в этой строчке:
observation = mgr.weather_at_place( message.text )
Она происходит из-за неправильных входных данных от пользователя.
Попробуйте добавить try ... except:

from pyowm import OWM
from pyowm.utils import config as cfg
import telebot


config = cfg.get_default_config()
config['language'] = 'ru'

owm = OWM('[token]', config)
bot = telebot.TeleBot("[token]")

@bot.message_handler(content_types=['text'])
def send_echo(message):
    mgr = owm.weather_manager()
    try:
        observation = mgr.weather_at_place( message.text )
    except:
        bot.send_message(message.chat.id, 'Извините, произошла ошибка')
    w = observation.weather
    temp = w.temperature('celsius') ["temp"]

    answer = "В городе " + message.text + " сейчас " + w.detailed_status + "\n"
    answer += "Температура там около " + str(temp) + "\n\n"

    if temp < 1:
        answer += "Сейчас очень холодно что пздц. Оденься как к походу На Северный полюс, иначе бубеньчики отморозишь!!!"
    elif temp < 10:
        answer += "Надень джинсы, да лёгкую куртку, а то на улице немного холодно"
    elif temp < 20:
        answer += "Сейчас на улице тепло, но лучше надень свитшот и джинсы"
    else:
        answer += "На улице жарко, что хоть в голым на улицу выходи"

    bot.send_message(message.chat.id, answer)

bot.polling( none_stop = True )
→ Ссылка