skip to Main Content

I am using Telebot (pyTelegramBotAPI) to run my telegram bot. I am running it on AWS within ECS in a Docker container.
Unfortunately, randomly it errors out: TeleBot: "Infinity polling exception: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
It might happen once a day or 20 times a day with random occurence.

At first I just used bot.polling(), then, following some advices online, I switched to more sophisticated:

while True:
    try:
        bot.infinity_polling(timeout=60, long_polling_timeout=60, none_stop=True)
    except Exception as e:
        print(f"Exception is: {e}")
        sleep(5)

Unfortunately, nothing helps and I still get the same error.

I also don’t understand how can infinity polling error happen if I added an exception handler to deal with it.
I would really appreciate your help, since I can find nothing online that helps to tackle the problem

2

Answers


  1. Got the same error but it looks the infinity_polling is continued nevertheless.

    It looks like a caught internal exception in TeleBot implement.

    Login or Signup to reply.
  2. It continues polling after the occurrence of the exception but it really is annoying. If you want it to skip logging, then set the logger_level parameter to less than logging.ERROR which is 50.

    bot.infinity_polling(logger_level=20)  # logger.INFO = 20
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search