File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed
Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -649,7 +649,8 @@ def getFile(self,
649649 def getUpdates (self ,
650650 offset = None ,
651651 limit = 100 ,
652- timeout = 0 ):
652+ timeout = 0 ,
653+ network_delay = 2 ):
653654 """Use this method to receive incoming updates using long polling.
654655
655656 Args:
@@ -665,6 +666,11 @@ def getUpdates(self,
665666 timeout:
666667 Timeout in seconds for long polling. Defaults to 0, i.e. usual
667668 short polling.
669+ network_delay:
670+ Additional timeout in seconds to allow the response from Telegram to
671+ take some time when using long polling. Defaults to 2, which should
672+ be enough for most connections. Increase it if it takes very long
673+ for data to be transmitted from and to the Telegram servers.
668674
669675 Returns:
670676 A list of telegram.Update objects are returned.
@@ -679,6 +685,8 @@ def getUpdates(self,
679685 data ['limit' ] = limit
680686 if timeout :
681687 data ['timeout' ] = timeout
688+ if network_delay :
689+ data ['network_delay' ] = network_delay
682690
683691 result = request .post (url , data )
684692
Original file line number Diff line number Diff line change @@ -79,10 +79,13 @@ def post(url,
7979 A JSON object.
8080 """
8181
82- # Add one second to the timeout of urlopen to allow data to be transferred
83- # over the network.
82+ # Add time to the timeout of urlopen to allow data to be transferred over
83+ # the network.
8484 if 'timeout' in data :
85- timeout = data ['timeout' ] + 1.
85+ if 'network_delay' in data :
86+ timeout = data ['timeout' ] + data ['network_delay' ]
87+ else :
88+ timeout = data ['timeout' ] + 2.
8689 else :
8790 timeout = None
8891
@@ -108,7 +111,7 @@ def post(url,
108111 message = _parse (error .read ())
109112 raise TelegramError (message )
110113 except SSLError as error :
111- if "The read operation timed out" == error .message :
114+ if "operation timed out" in error .message :
112115 raise TelegramError ("Timed out" )
113116
114117 raise TelegramError (error .message )
You can’t perform that action at this time.
0 commit comments