Answer the question
In order to leave comments, you need to log in
When starting the telegram-bot program, an incomprehensible error occurs to me. help?
It looks like this - "A request to the Telegram API was unsuccessful. Error code: 401. Description: Unauthorized" The
bot token was changed to a new one and it still crashes.
Below I attach the code of my program, the tokens are slightly changed. Has anyone else experienced this and figured out what's wrong?
import telebot
from pyowm.owm import OWM
from pyowm.utils.config import get_default_config
config_dict = get_default_config()
config_dict['language'] = 'ru'
owm = OWM('205d4059ce16fabc1e4d839823f', config_dict)
mgr = owm.weather_manager()
bot = telebot.TeleBot("1731282334:AAFFrdO9120tWO9RZuw5I0HiLcZebNhg", parse_mode=None)
@bot.message_handler(func=lambda m: True)
def echo_all(message):
observation = mgr.weather_at_place(message.text)
w = observation.weather
temp = w.temperature('celsius') ['temp']
speed = w.wind() ['speed']
answer = 'В городе ' + message.text + 'сейчас ' + w.detailed_status + '\n'
answer += ' Температура сейчас в районе ' + str(temp) + '\n'
answer += ' Cкорость ветра равна ' + str(speed) + ' м/c' + '\n'
if temp < 10:
answer += 'Сейчас очень холодно,одевайся тепло!'
elif temp < 20:
answer += 'Сейчас холодно'
else:
answer += 'На улице тепло!'
bot.send_message(message.chat.id, answer)
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question