При выполнения кода, вылезает ошибка, но при выполнении этого кода не в телеграмм боте всё отлично. p.s бот на хостинге pythonanywhere поэтому python 2.7 (возможно поэтому и ошибка, у меня 3.8) код:
@bot.message_handler(commands=['weather'])
def send_welcome(message):
msg = bot.reply_to(message, """
В каком городе вы хотите узнать погоду?
""")
bot.register_next_step_handler(msg, process_weather_step)
def process_weather_step(message):
chat_id = message.chat.id
user_text = message.text
observation = owm.weather_at_place(str(user_text))
w = observation.get_weather()
temp = w.get_temperature('celsius')['temp']
status = w.get_detailed_status()
response = ('''
В городе '{0}' сейчас:
* {1} °C
* {2}
'''.format(user_text,temp,status))
bot.send_message(message.chat.id, '{}'.format(response))
ошибка:
2020-02-26 17:07:36,649 (util.py:66 WorkerThread1) ERROR - TeleBot: "UnicodeEncodeError occurred, args=('ascii', u'\u041c\u0438\u043d\u0441\u043a', 0, 5, 'ordinal no
t in range(128)')
Traceback (most recent call last):
File "/home/Qvint01/.local/lib/python2.7/site-packages/telebot/util.py", line 60, in run
task(*args, **kwargs)
File "bot.py", line 126, in process_weather_step
observation = owm.weather_at_place(str(user_text))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)
"
Traceback (most recent call last):
File "bot.py", line 174, in <module>
bot.polling(none_stop=True)
File "/home/Qvint01/.local/lib/python2.7/site-packages/telebot/__init__.py", line 392, in polling
self.__threaded_polling(none_stop, interval, timeout)
File "/home/Qvint01/.local/lib/python2.7/site-packages/telebot/__init__.py", line 416, in __threaded_polling
self.worker_pool.raise_exceptions()
File "/home/Qvint01/.local/lib/python2.7/site-packages/telebot/util.py", line 109, in raise_exceptions
six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
File "/home/Qvint01/.local/lib/python2.7/site-packages/telebot/util.py", line 60, in run
task(*args, **kwargs)
File "bot.py", line 126, in process_weather_step
observation = owm.weather_at_place(str(user_text))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)
Exception in thread WorkerThread1 (most likely raised during interpreter shutdown):Exception in thread WorkerThread2 (most likely raised during interpreter shutdown)
:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
File "/home/Qvint01/.local/lib/python2.7/site-packages/telebot/util.py", line 66, in run
<type 'exceptions.TypeError'>: 'NoneType' object is not callable
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
File "/home/Qvint01/.local/lib/python2.7/site-packages/telebot/util.py", line 66, in run
<type 'exceptions.TypeError'>: 'NoneType' object is not callable
Заранее спасибо