File tree 1 file changed +5
-16
lines changed
1 file changed +5
-16
lines changed Original file line number Diff line number Diff line change 6
6
7
7
import logging
8
8
import telegram
9
+ from telegram .error import NetworkError , Unauthorized
9
10
from time import sleep
10
11
11
- try :
12
- from urllib .error import URLError
13
- except ImportError :
14
- from urllib2 import URLError # python 2
15
-
16
12
17
13
def main ():
18
14
# Telegram Bot Authorization Token
@@ -31,18 +27,11 @@ def main():
31
27
while True :
32
28
try :
33
29
update_id = echo (bot , update_id )
34
- except telegram .TelegramError as e :
35
- # These are network problems with Telegram.
36
- if e .message in ("Bad Gateway" , "Timed out" ):
37
- sleep (1 )
38
- elif e .message == "Unauthorized" :
39
- # The user has removed or blocked the bot.
40
- update_id += 1
41
- else :
42
- raise e
43
- except URLError as e :
44
- # These are network problems on our end.
30
+ except NetworkError :
45
31
sleep (1 )
32
+ except Unauthorized :
33
+ # The user has removed or blocked the bot.
34
+ update_id += 1
46
35
47
36
48
37
def echo (bot , update_id ):
You can’t perform that action at this time.
0 commit comments