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,
649
649
def getUpdates (self ,
650
650
offset = None ,
651
651
limit = 100 ,
652
- timeout = 0 ):
652
+ timeout = 0 ,
653
+ network_delay = 2 ):
653
654
"""Use this method to receive incoming updates using long polling.
654
655
655
656
Args:
@@ -665,6 +666,11 @@ def getUpdates(self,
665
666
timeout:
666
667
Timeout in seconds for long polling. Defaults to 0, i.e. usual
667
668
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.
668
674
669
675
Returns:
670
676
A list of telegram.Update objects are returned.
@@ -679,6 +685,8 @@ def getUpdates(self,
679
685
data ['limit' ] = limit
680
686
if timeout :
681
687
data ['timeout' ] = timeout
688
+ if network_delay :
689
+ data ['network_delay' ] = network_delay
682
690
683
691
result = request .post (url , data )
684
692
Original file line number Diff line number Diff line change @@ -79,10 +79,13 @@ def post(url,
79
79
A JSON object.
80
80
"""
81
81
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.
84
84
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.
86
89
else :
87
90
timeout = None
88
91
@@ -108,7 +111,7 @@ def post(url,
108
111
message = _parse (error .read ())
109
112
raise TelegramError (message )
110
113
except SSLError as error :
111
- if "The read operation timed out" == error .message :
114
+ if "operation timed out" in error .message :
112
115
raise TelegramError ("Timed out" )
113
116
114
117
raise TelegramError (error .message )
You can’t perform that action at this time.
0 commit comments