Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR - TeleBot: "ConnectionError occurred, args=(ProtocolError('Connection aborted.', TimeoutError(110, 'Connection timed out')),) #453

Closed
toxidxd opened this issue Jan 29, 2018 · 34 comments

Comments

@toxidxd
Copy link

toxidxd commented Jan 29, 2018

2018-01-29 08:32:07,077 (util.py:64 WorkerThread1) ERROR - TeleBot: "ConnectionError occurred, args=(ProtocolError('Connection aborted.', TimeoutError(110, 'Connection timed out')),)
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 560, in urlopen
body=body, headers=headers)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.5/http/client.py", line 1106, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
self.endheaders(body)
File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
self._send_output(message_body)
File "/usr/lib/python3.5/http/client.py", line 936, in _send_output
self.send(message_body)
File "/usr/lib/python3.5/http/client.py", line 908, in send
self.sock.sendall(data)
File "/usr/lib/python3.5/ssl.py", line 891, in sendall
v = self.send(data[count:])
File "/usr/lib/python3.5/ssl.py", line 861, in send
return self._sslobj.write(data)
File "/usr/lib/python3.5/ssl.py", line 586, in write
return self._sslobj.write(data)
TimeoutError: [Errno 110] Connection timed out

  1. What version of pyTelegramBotAPI are you using?
    Name: pyTelegramBotAPI
    Version: 3.5.2

  2. What OS are you using?
    Linux Mint 18.2

  3. What version of python are you using?
    Python 3.5.2

@eternnoir
Copy link
Owner

Is it always happen? It seems network problem between your device and telegram bot api server.

@eatbas
Copy link

eatbas commented Feb 7, 2018

Same here after like an 10 min bot gets disconnected help pls

@eatbas
Copy link

eatbas commented Feb 10, 2018

@eternnoir hello man it happens all the time for me. If i leave the bot un attended like 10 min. I instantly get this error. I am using latest version of the bot, windows 10 pycharm and python version 3.5.2 waiting for your answer. I can send the code if you like mostly I am using

bot.register_next_step_handler(msg, trade_type_step)

Waiting for your reply.

@eternnoir
Copy link
Owner

@eatbas It seems like network problem not package problem. Try some vps to test it.

@i3wangyi
Copy link

It's always happening on my side as well, I feel like polling method doesn't handle the network failure exception properly (as it only catches ApiException and KeyBoardInterrupt exception) , at least allow several retries is needed.

@AInsane
Copy link

AInsane commented Mar 13, 2018

Had the same problem!!!

python 3.6
pyTrlrgramBotAPI - latest

webhook (flask) as in example: https://github.com/eternnoir/pyTelegramBotAPI/blob/master/examples/webhook_examples/webhook_flask_echo_bot.py

CentOS7
Host on - Google cloud service (Virtual Mashine)

If i don`t speak with my bot above 15min it 'sleep' and the first message give this error
Mar 13 11:08:09 instance-1 python3.6[15983]: 2018-03-13 11:08:09,872 (util.py:65 WorkerThread1) ERROR - TeleBot: "ConnectionError occurred, args=(ProtocolError('Connect
ion aborted.', ConnectionResetError(104, 'Connection reset by peer')),)
.......
ConnectionError(err, request=request)
Mar 13 11:08:09 instance-1 python3.6[15983]: requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
Mar 13 11:08:09 instance-1 python3.6[15983]: "

And wit the next messages - everything OK!

Mar 13 11:08:13 instance-1 python3.6[15983]: 149.154.167.226 - - [13/Mar/2018 11:08:13] "POST /TOKEN/ HTTP/1.1" 200 -

@Stihotvor
Copy link

Same as above. Tested on GCE Ubuntu 18.04

@jekeam
Copy link

jekeam commented Apr 17, 2019

+1, after 10-15 min:
(util.py:65 WorkerThread2) ERROR - TeleBot: "ConnectionError occurred, args=(ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')),)

@haliliceylan
Copy link

+1

3 similar comments
@aever32
Copy link

aever32 commented Aug 20, 2019

+1

@hieupmse05244
Copy link

+1

@fira42073
Copy link

+1

@LiadBarnes
Copy link

LiadBarnes commented Sep 10, 2019

Hi same here but 104

requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

no solution yet?
I mean for me it working perfect while running on my private pc
but on gcloud it just happen all the time this error

EDIT
found that it was happen to me only on gcloud vm instance,
moved to aws and everything is perfect.
something wrong with google and requests lib
take care

@YurkaGagarin
Copy link

I have the issue too.
I work on Google DataLab and use telebot lib.
It happen just about after 10 minutes.
I don't use requests lib

@ghost
Copy link

ghost commented Oct 4, 2019

+1. This happens when I try to send a voice message.

@ghost
Copy link

ghost commented Oct 4, 2019

Solved the problem by sending a smaller file)))).

@TahirJalilov
Copy link

Hello, the same problem for my bit in google cloud vm. Previously my bot was on hetzner and everything was good. Does anyone know how to automatically restart bot if i catch this error?

@YurkaGagarin
Copy link

I solved the issue by following function:

def solver(text):
  try:
    msg = InvestingcomPythonEchoBot.send_message(chat_id=XXXXXXXXXXXXXXX, text=text)
  except OSError:
    msg = InvestingcomPythonEchoBot.send_message(chat_id=XXXXXXXXXXXXXXX, text=text)
solver('Problem solved')

@TahirJalilov
Copy link

I solved the issue by following function:

def solver(text):
  try:
    msg = InvestingcomPythonEchoBot.send_message(chat_id=XXXXXXXXXXXXXXX, text=text)
  except OSError:
    msg = InvestingcomPythonEchoBot.send_message(chat_id=XXXXXXXXXXXXXXX, text=text)
solver('Problem solved')

well, as I understood you try to catch OSError every time during sending a message. Correct?

@fira42073
Copy link

fira42073 commented Oct 7, 2019 via email

@TahirJalilov
Copy link

TahirJalilov commented Oct 7, 2019

I did like that:

def send_msg(telegram_id, msg):
    try:
        bot.send_message(telegram_id, msg)
    except (ConnectionAbortedError, ConnectionResetError, ConnectionRefusedError, ConnectionError):
        print("ConnectionError - Sending again after 5 seconds!!!")
        time.sleep(5)
        bot.send_message(telegram_id, msg)

Then I did testing with continuously sending a lot of messages to the bot and everything looks good.

@TahirJalilov
Copy link

also, you can create cron job which will be check if a bot is not running, start bot
*/1 * * * * ps -aux | grep grep -v |grep bot.py > /home/user/cronresult.txt || python3 /home/user/TelegramBot/bot.py -args0 -args1

@fira42073
Copy link

fira42073 commented Oct 8, 2019 via email

@Badiboy Badiboy closed this as completed Jan 3, 2020
@seriousidea
Copy link

I have the same problem on Google Compute Engine + Debian 9 + pyTelegramBotAPI 3.7.1

@raitonoberu
Copy link

My solution:

telebot.apihelper.READ_TIMEOUT = 5

def send_msg(text, id):
    try:
        bot.send_message(id, text)
    except Exception as e:
        logging.info(e)
        send_msg(text, id)

@janith989
Copy link

I also faced to this issue.any solution?

@mishagavura
Copy link

But when to call this function?


def send_msg(telegram_id, msg):
    try:
        bot.send_message(telegram_id, msg)
    except (ConnectionAbortedError, ConnectionResetError, ConnectionRefusedError, ConnectionError):
        print("ConnectionError - Sending again after 5 seconds!!!")
        time.sleep(5)
        bot.send_message(telegram_id, msg)

Like I understood the code, but when should I call this function? Can anybody send an example?

@camilo-cf
Copy link

I had the same issue. I adapted this solution to my requirements and worked very well.

My solution:

telebot.apihelper.READ_TIMEOUT = 5

def send_msg(text, id):
    try:
        bot.send_message(id, text)
    except Exception as e:
        logging.info(e)
        send_msg(text, id)

Thank you!!!

@amats6655
Copy link

None of these solutions helped .. every 10-15 minutes of inactivity connection rushes with an error =(

"Connectionerror Occurred, Args = (Protocolerror ('Connection ABORTED.", ConnectionReseTerror (104,' Connection Reset by Peer ')))

@Xh0st
Copy link

Xh0st commented Jun 18, 2021

None of these solutions helped .. every 10-15 minutes of inactivity connection rushes with an error =(

"Connectionerror Occurred, Args = (Protocolerror ('Connection ABORTED.", ConnectionReseTerror (104,' Connection Reset by Peer ')))

Have you solved? I'm having the same issue.
working with bot.infinity_polling()
but after inactivity it need 2 or 3 command's to respond

@pompushko
Copy link

I have the same problem on Google Compute Engine + Debian 10 + pyTelegramBotAPI 3.8.2

@excitoon
Copy link

excitoon commented Sep 9, 2021

Why it is closed? What is the cause of it? Wrong default poll interval? @eternnoir

@excitoon
Copy link

excitoon commented Sep 9, 2021

I guess we can tune connection pool to solve this.

@excitoon
Copy link

excitoon commented Sep 9, 2021

Why SESSION_TIME_TO_LIVE is hard-coded to None?

JonasCaetanoSz added a commit to JonasCaetanoSz/PaymentsBot that referenced this issue Aug 27, 2023
esse erro é citado em: eternnoir/pyTelegramBotAPI#453. a alteração faz o bot se auto reiniciar em caso exeção
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests