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

TimedOut on get_updates #802

Closed
misha-antonenko opened this issue Aug 16, 2017 · 17 comments · Fixed by #1007
Closed

TimedOut on get_updates #802

misha-antonenko opened this issue Aug 16, 2017 · 17 comments · Fixed by #1007
Assignees

Comments

@misha-antonenko
Copy link

Calling get_updates consistently crashes the bot with telegram.error.TimedOut: Timed out .

The code:

updates = self.bot.get_updates(
    offset=self.update_id,
    timeout=30,
    network_delay=1.0
)

The log:

Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 402, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 398, in _make_request
    httplib_response = conn.getresponse()
  File "/app/.heroku/python/lib/python3.6/http/client.py", line 1331, in getresponse
    response.begin()
  File "/app/.heroku/python/lib/python3.6/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/app/.heroku/python/lib/python3.6/http/client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/app/.heroku/python/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
  File "/app/.heroku/python/lib/python3.6/ssl.py", line 1002, in recv_into
    return self.read(nbytes, buffer)
  File "/app/.heroku/python/lib/python3.6/ssl.py", line 865, in read
    return self._sslobj.read(len, buffer)
  File "/app/.heroku/python/lib/python3.6/ssl.py", line 625, in read
    v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/utils/request.py", line 174, in _request_wrapper
    resp = self._con_pool.request(*args, **kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/vendor/ptb_urllib3/urllib3/request.py", line 70, in request
    **urlopen_kw)
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/vendor/ptb_urllib3/urllib3/request.py", line 148, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/vendor/ptb_urllib3/urllib3/poolmanager.py", line 244, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 666, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/vendor/ptb_urllib3/urllib3/util/retry.py", line 347, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/vendor/ptb_urllib3/urllib3/packages/six.py", line 686, in reraise
    raise value
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 617, in urlopen
    chunked=chunked)
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 405, in _make_request
    exc_cls=ReadTimeoutError)
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 321, in _raise_timeout
    raise exc_cls(*args)
telegram.vendor.ptb_urllib3.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=31.0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/myapp/bot.py", line 81, in update_forever
    network_delay=1.0
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/bot.py", line 52, in decorator
    result = func(self, *args, **kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/bot.py", line 1392, in get_updates
    result = self._request.post(url, data, timeout=float(read_latency) + float(timeout))
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/utils/request.py", line 252, in post
    **urlopen_kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/telegram/utils/request.py", line 176, in _request_wrapper
    raise TimedOut()
telegram.error.TimedOut: Timed out
@mendiej
Copy link

mendiej commented Aug 18, 2017

I encounter the same issue/error (socket.timeout). For getUpdates, timeout set to anything but 0 results in errors. They are way less frequent when leaving out the timeout parameter, but they still do occur.

@jh0ker
Copy link
Member

jh0ker commented Sep 21, 2017

FYI the network_delay parameter is deprecated (at least in the latest version), so instead you should be using the read_latency parameter. And perhaps choosing a higher value for this parameter could solve your issue?

@Andreychik32
Copy link

I have the same issue. Changing the read_latency parameter seems to not do any work on this issue.

@tsnoam
Copy link
Member

tsnoam commented Oct 11, 2017

Hi,
I'm sorry for my very late response.
@levzhazeschi - the problem with long polling is that you might lose connection without the application even knowing it.
In order to debug network problems we must have much more data. The first things to check (but upon adding the data, more questions will probably rise):

  1. Where do you host your bot? I see "heroku", but what region?
  2. Followup to 1 - have you measured the latency towards api.telegram.org ?
  3. Do you get the error you described immediately at the first get_updates attempt or after several successful iterations?
  4. If after several iterations:
    4.1. How many iterations until failure?
    4.2 How long before failure?
  5. To answer 4, and in general, please enable debug logging from ptb and upload logs with more context - before and after the failure.

@tsnoam tsnoam self-assigned this Oct 11, 2017
@sutyrin
Copy link

sutyrin commented Dec 16, 2017

Hey folks!

I've very affected by this. Is there a quickfix to just ignore these and silently reconnect, if needed?

Are patches welcome, eh? ;)

@Shadowigor
Copy link

Is there any progress on this? I can still reproduce this with the newest version, I start getting the errors after about 30 minutes of inactivity.

@sobolevn
Copy link

sobolevn commented Feb 8, 2018

I also have this error.

@Logerfo
Copy link

Logerfo commented Feb 8, 2018

I had this issue using heroku. The problem was that my Procfile started with web. I changed it to bot and worked like a charm!

tsnoam added a commit that referenced this issue Feb 15, 2018
TimedOut exception is an expected an normal event. To reduce noise and
make things more "fluent" we now:
 - Make sure that we don't sleep after the timeout but rather retry
immediately.
 - Log debug instead of error level.

Fixes #802
@tsnoam
Copy link
Member

tsnoam commented Feb 18, 2018

Hi,
Please see the recently uploaded wiki article about network errors:
https://github.com/python-telegram-bot/python-telegram-bot/wiki/Handling-network-errors

I hope it will answer why a timeout is (unfortunately) an unavoidable condition and will give you some hints on how to fine tune your bot.

In addition, once PR #1007 will be merged, there will be a better handling of timeouts during get_updates (that merge should happen today).

@tsnoam tsnoam closed this as completed Feb 18, 2018
tsnoam added a commit that referenced this issue Feb 18, 2018
TimedOut exception is an expected an normal event. To reduce noise and
make things more "fluent" we now:
 - Make sure that we don't sleep after the timeout but rather retry
immediately.
 - Log debug instead of error level.

Fixes #802
@yongman
Copy link

yongman commented Apr 29, 2018

I also have this problem.

@Andreychik32
Copy link

@yongman, just update python-telegram-bot using this command:

pip install -U python-telegram-bot

@yongman
Copy link

yongman commented Apr 29, 2018

@Andreychik32 ,Thanks for you reply.

I update the python-telegram-bot by pip3, but I also get the following errors.

2018-04-29 06:37:47,954 [Level 99]: ehforwarderbot.__main__ (__main__.init; __main__.py:87)
     Initializing master blueset.telegram...
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 402, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/usr/local/lib/python3.6/dist-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 398, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.6/http/client.py", line 1331, in getresponse
    response.begin()
  File "/usr/lib/python3.6/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.6/http/client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
  File "/usr/lib/python3.6/ssl.py", line 1009, in recv_into
    return self.read(nbytes, buffer)
  File "/usr/lib/python3.6/ssl.py", line 871, in read
    return self._sslobj.read(len, buffer)
  File "/usr/lib/python3.6/ssl.py", line 631, in read
    v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 617, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.6/dist-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 405, in _make_request
    exc_cls=ReadTimeoutError)
  File "/usr/local/lib/python3.6/dist-packages/telegram/vendor/ptb_urllib3/urllib3/connectionpool.py", line 321, in _raise_timeout
    raise exc_cls(*args)
telegram.vendor.ptb_urllib3.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=9)

During handling of the above exception, another exception occurred:

and the bot exit.

By the way, the network from my vps to api.telegram.org:443 seems good.

@yongman
Copy link

yongman commented Apr 29, 2018

More to say, this error occur from today and bot cannot work as before.

@Brawl345
Copy link

Brawl345 commented Apr 29, 2018

Telegram currently has a power outage: https://twitter.com/telegram/status/990474364108894209
Bots are not working atm in some regions.

@yongman
Copy link

yongman commented Apr 29, 2018

@Brawl345 Thanks for your information.

It seems the telegram's problem, but the python-telegram-bot also have the bug if timeout exists?

@tsnoam
Copy link
Member

tsnoam commented Apr 29, 2018

@yongman
I invite you to join our users group where we have a vibrant community helping each other: https://telegram.me/pythontelegrambotgroup

As suggested in one of the earlier comments please make sure to read the wiki page: https://telegram.me/pythontelegrambotgroup

If you've identified an actual bug with the library please open a new issue instead of reviving an old one.

@python-telegram-bot python-telegram-bot locked as resolved and limited conversation to collaborators Apr 29, 2018
@tsnoam
Copy link
Member

tsnoam commented Apr 29, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.