Read timed out. (read timeout=30) Error
Please answer these questions before submitting your issue. Thanks!
- What version of pyTelegramBotAPI are you using? six-1.11.0
- What OS are you using? Ubuntu 14.04.4 LTS
- 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
I have the exact same problem
Just use webhook...
def polling(self, none_stop=False, interval=0, timeout=20):
you should increase the timeout
Same as #473
bot.infinity_polling(True)
@M1LKYWVY this implemented by infinity_polling
@sviat9440 I don't know which version pytelegrambotapi u use, but in 3.6.2 I don't have such method.
@M1LKYWVY please download the lasted source code.
@M1LKYWVY #487
@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 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.
@Sajjadhosn please download "telebot" folder in root of your bot directory or wait for 3.6.3 release.
@Sajjadhosn is not correct solution
Any update?
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 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.
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