A
A
AlexSn20202020-07-07 16:43:26
Python
AlexSn2020, 2020-07-07 16:43:26

Why is the bot interrupted?

Hello! The problem is the following: when you start the bot, it works fine for a while, but then, when you don’t access it for 10-15 minutes, an error occurs:

raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'Удаленный хост принудительно разорвал существующее подключение', None, 10054, None))

Can you tell me what is the problem? I'm running it on my computer, maybe if I put it on hosting, an error will not fly out?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Zhig, 2020-07-13
@AlexSn2020

This is a problem on the side of the telebot library. There are two ways out:
1) You set the program to run using the systemd utility. In it, in the [service] setting, specify Restart=on-failure. In this case, if the script terminates, systemd will restart it. Well, or put a restart every 30-60 minutes.
2) You pass and rewrite on aiogram. In 2015-2017, perhaps, telebot was relevant, but progress does not stand still. And telebot, alas, is worth it. Poor polling implementation, problematic next_step_handler, slow support for new Bot API versions, etc.
Arguments for switching to aiogram:

  1. it is a complete framework, i.e. allows you to do more useful things;
  2. asynchronous, which makes it faster in some tasks;
  3. Python 3.7+ and higher are supported, which will encourage you to update your old interpreter and use the new features of the language;
  4. many built-in "helpers" (syntactic "sugar") that improve the readability of the code;
  5. operational updates (support for new surveys appeared on the same day as in the Bot API itself);
  6. Russian-language support and discussion chat, where the developer of the framework sits, among other things;
  7. my favorite point: normally working polling.

( https://mastergroosha.github.io/telegram-tutorial/...
Personally, I chose the second way.

R
Renat Ataev, 2020-07-08
@fanepka

Take in try / except and set a timer

try:
     #Твой код

except:
     time.sleep(10) # Таймер на 10 секунд

S
skilet16, 2020-07-08
@skilet16

while True:
    try:
        bot.polling(none_stop=True)

    except Exception as e:
        print(e) 
      
        time.sleep(15)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question