pyTelegramBotAPI icon indicating copy to clipboard operation
pyTelegramBotAPI copied to clipboard

Read timed out. (read timeout=30) Error

Open natijauskas opened this issue 8 years ago • 17 comments

Please answer these questions before submitting your issue. Thanks!

  1. What version of pyTelegramBotAPI are you using? six-1.11.0
  2. What OS are you using? Ubuntu 14.04.4 LTS
  3. What version of python are you using? Python 3.4.3

Hello! I have had this error several times in the past few days and I can not fix it. I use this solution in my code (#251) but I have the same error. Can you help me? Thanks a lot!

while True:

try:

    bot.polling(none_stop=True)

# ConnectionError and ReadTimeout because of possible timout of the requests library

# TypeError for moviepy errors

# maybe there are others, therefore Exception

except Exception as e:

    logger.error(e)

    time.sleep(15)

File "/usr/local/lib/python3.4/dist-packages/telebot/apihelper.py", line 54, in _make_request timeout=(connect_timeout, read_timeout), proxies=proxy) File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 508, in request resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 618, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 521, in send raise ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=30)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "bot.py", line 537, in logger.error(e)

natijauskas avatar Mar 13 '18 22:03 natijauskas

I have the exact same problem

marting87 avatar Mar 14 '18 10:03 marting87

Just use webhook...

SkymanOne avatar Mar 20 '18 20:03 SkymanOne

def polling(self, none_stop=False, interval=0, timeout=20):

you should increase the timeout

heyyyoyy avatar Apr 01 '18 12:04 heyyyoyy

Same as #473

sviat9440 avatar Apr 02 '18 14:04 sviat9440

bot.infinity_polling(True)

sviat9440 avatar Apr 10 '18 10:04 sviat9440

@M1LKYWVY this implemented by infinity_polling

sviat9440 avatar Apr 10 '18 20:04 sviat9440

@sviat9440 I don't know which version pytelegrambotapi u use, but in 3.6.2 I don't have such method.

M1LKYWVY avatar Apr 10 '18 20:04 M1LKYWVY

@M1LKYWVY please download the lasted source code.

sviat9440 avatar Apr 10 '18 20:04 sviat9440

@M1LKYWVY #487

sviat9440 avatar Apr 10 '18 20:04 sviat9440

@sviat9440 Have downloaded your improvements, but bot still falling down. Nay with your commit. ERROR - TeleBot: "ConnectionError occurred, args=(ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)),) As I understood it is a bug of this api, hope it will be eliminated in future versions.

M1LKYWVY avatar Apr 10 '18 21:04 M1LKYWVY

@M1LKYWVY can't confirm a problem, I have 10 days uptime. Try creating a new project and use this method. If the problem still down, please contact.

sviat9440 avatar Apr 15 '18 04:04 sviat9440

@Sajjadhosn please download "telebot" folder in root of your bot directory or wait for 3.6.3 release.

sviat9440 avatar Apr 18 '18 11:04 sviat9440

@Sajjadhosn is not correct solution

sviat9440 avatar Apr 18 '18 11:04 sviat9440

Any update?

Stihotvor avatar Jun 13 '18 09:06 Stihotvor

Got same problem. Infinity_pooling didn't help. I got such error message:

2018-07-01 11:54:39,273 (util.py:65 PollingThread) ERROR - TeleBot: "ConnectionError occurred, args=(ProtocolError('Connection aborted.', error(101, 'Network is unreachable')),)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/telebot/util.py", line 59, in run
    task(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/telebot/__init__.py", line 158, in __retrieve_updates
    updates = self.get_updates(offset=(self.last_update_id + 1), timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/telebot/__init__.py", line 128, in get_updates
    json_updates = apihelper.get_updates(self.token, offset, limit, timeout, allowed_updates)
  File "/usr/local/lib/python2.7/dist-packages/telebot/apihelper.py", line 180, in get_updates
    return _make_request(token, method_url, params=payload)
  File "/usr/local/lib/python2.7/dist-packages/telebot/apihelper.py", line 54, in _make_request
    timeout=(connect_timeout, read_timeout), proxies=proxy)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 415, in send
    raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', error(101, 'Network is unreachable'))
"

sallyruthstruik avatar Jul 01 '18 08:07 sallyruthstruik

@sallyruthstruik Problem can be solved by increasing timeout in polling function. I used bot.polling(none_stop=True, timeout=123). I have more than 15 days uptime with this method.

M1LKYWVY avatar Jul 02 '18 06:07 M1LKYWVY

The following fixed it for me:

Change Line 53:

 result = _get_req_session().request(method, request_url, params=params, files=files,
                                        timeout=(connect_timeout, read_timeout), proxies=proxy)
    logger.debug("The server returned: '{0}'".format(result.text.encode('utf8')))
    return _check_result(method_name, result)['result']

To:

while True:
        try:
            result = _get_req_session().request(method, request_url, params=params, files=files,
                                            timeout=(connect_timeout, read_timeout), proxies=proxy)

            logger.debug("The server returned: '{0}'".format(result.text.encode('utf8')))
            return _check_result(method_name, result)['result']

        except:
            time.sleep(5);

Don't forget to import time

marting87 avatar Jul 02 '18 07:07 marting87