mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-23 06:50:29 +01:00
Add parameter network_delay for slow connections and increase default to 2 seconds
This commit is contained in:
parent
9191d333ca
commit
4bc03ed56a
2 changed files with 16 additions and 5 deletions
|
@ -649,7 +649,8 @@ class Bot(TelegramObject):
|
|||
def getUpdates(self,
|
||||
offset=None,
|
||||
limit=100,
|
||||
timeout=0):
|
||||
timeout=0,
|
||||
network_delay=2):
|
||||
"""Use this method to receive incoming updates using long polling.
|
||||
|
||||
Args:
|
||||
|
@ -665,6 +666,11 @@ class Bot(TelegramObject):
|
|||
timeout:
|
||||
Timeout in seconds for long polling. Defaults to 0, i.e. usual
|
||||
short polling.
|
||||
network_delay:
|
||||
Additional timeout in seconds to allow the response from Telegram to
|
||||
take some time when using long polling. Defaults to 2, which should
|
||||
be enough for most connections. Increase it if it takes very long
|
||||
for data to be transmitted from and to the Telegram servers.
|
||||
|
||||
Returns:
|
||||
A list of telegram.Update objects are returned.
|
||||
|
@ -679,6 +685,8 @@ class Bot(TelegramObject):
|
|||
data['limit'] = limit
|
||||
if timeout:
|
||||
data['timeout'] = timeout
|
||||
if network_delay:
|
||||
data['network_delay'] = network_delay
|
||||
|
||||
result = request.post(url, data)
|
||||
|
||||
|
|
|
@ -79,10 +79,13 @@ def post(url,
|
|||
A JSON object.
|
||||
"""
|
||||
|
||||
# Add one second to the timeout of urlopen to allow data to be transferred
|
||||
# over the network.
|
||||
# Add time to the timeout of urlopen to allow data to be transferred over
|
||||
# the network.
|
||||
if 'timeout' in data:
|
||||
timeout = data['timeout'] + 1.
|
||||
if 'network_delay' in data:
|
||||
timeout = data['timeout'] + data['network_delay']
|
||||
else:
|
||||
timeout = data['timeout'] + 2.
|
||||
else:
|
||||
timeout = None
|
||||
|
||||
|
@ -108,7 +111,7 @@ def post(url,
|
|||
message = _parse(error.read())
|
||||
raise TelegramError(message)
|
||||
except SSLError as error:
|
||||
if "The read operation timed out" == error.message:
|
||||
if "operation timed out" in error.message:
|
||||
raise TelegramError("Timed out")
|
||||
|
||||
raise TelegramError(error.message)
|
||||
|
|
Loading…
Reference in a new issue