
Арсений
05.12.2018
18:10:34
Почему не работает такой код? Если бот падает при telebot.apihelper.ApiException, ни один из except не срабатывает
try:
db_tools.set_db()
db.db.connect()
bot.send_message(MY_CHAT_ID, '*Снова в строю!*', parse_mode=md)
print(f'\nPolling from {BOTS[TOKEN]}')
bot.polling(none_stop=False, timeout=20)
except requests.exceptions.ReadTimeout:
raise
except Exception as e:
text = ANSWERS['EXCEPTION'].format(error=str(e))
bot.send_message(MY_CHAT_ID, text, parse_mode=md, disable_notification=True)
with open(f'logs/{start_time}.log', 'r', encoding='utf-8') as file:
bot.send_document(MY_CHAT_ID, file, disable_notification=True)
raise e
finally:
db.db.close()
С любыми другими исключениями рабоатет как ожидается, finaly отрабатывает в любом случае