Skip to content

[BUG] Errors when stopping bot with CTRL-C #3006

@super22n

Description

@super22n

Issue I am facing

When I stop the bot by pressing CTRL-C, I get several errors printed out. This didn't happen with the older version of python-telegram-bot.
The errors can be seen in the traceback. Do I need to catch those errors in the error handler?

Traceback to the issue

^C2022-05-07 15:46:38,842 - telegram.ext._updater - ERROR - Error while getting Updates: Unknown error in HTTP implementation: CancelledError()
Update None caused error Unknown error in HTTP implementation: CancelledError()
2022-05-07 15:46:38,842 - telegram.ext._application - ERROR - An error was raised and an uncaught error was raised while handling the error with an error_handler.
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/python_telegram_bot-20.0a0-py3.7.egg/telegram/ext/_application.py", line 1445, in process_error
    await callback(update, context)
TypeError: object NoneType can't be used in 'await' expression
2022-05-07 15:46:39,844 - telegram.ext._application - INFO - Application is stopping. This might take a moment.
2022-05-07 15:46:39,845 - apscheduler.scheduler - INFO - Scheduler has been shut down
2022-05-07 15:46:39,856 - telegram.ext._application - INFO - Application.stop() complete

Related part of your code

import logging
from telegram import Update
from telegram.ext import Application, CallbackContext, CommandHandler

logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    level=logging.INFO
)

def error(update, context):
        print(f"Update {update} caused error {context.error}")

async def start(update: Update, context: CallbackContext.DEFAULT_TYPE):
    await context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a bot, please talk to me!")

if __name__ == '__main__':
    application = Application.builder().token('TOKEN').build()
    start_handler = CommandHandler('start', start)
    application.add_handler(start_handler)
    application.add_error_handler(error)
    application.run_polling()

Operating System

Debian 10

Version of Python, python-telegram-bot & dependencies

python-telegram-bot 20.0a0
Bot API 6.0
Python 3.7.3 (default, Jan 22 2021, 20:04:44)  [GCC 8.3.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions