@@ -37,44 +37,32 @@ def do_check(url):
37
37
try :
38
38
response = _urllib .request .urlopen (request , timeout = settings .TIMEOUT )
39
39
return response
40
- except Exception as err :
41
- if "Connection refused" in str (err ):
42
- err_msg = "Unable to connect to the target URL or proxy ("
43
- err_msg += str (menu .options .proxy )
44
- err_msg += ")."
45
- print (settings .print_critical_msg (err_msg ))
46
- raise SystemExit ()
40
+ except (_urllib .error .URLError , _urllib .error .HTTPError , _http_client .BadStatusLine ) as err :
41
+ err_msg = "Unable to connect to the target URL or proxy."
42
+ print (settings .print_critical_msg (err_msg ))
43
+ raise SystemExit ()
47
44
48
45
"""
49
46
Use the defined HTTP Proxy
50
47
"""
51
48
def use_proxy (request ):
49
+ _ = True
52
50
headers .do_check (request )
53
51
request .set_proxy (menu .options .proxy , settings .PROXY_SCHEME )
54
52
try :
55
53
response = _urllib .request .urlopen (request , timeout = settings .TIMEOUT )
56
54
return response
57
- except _http_client .BadStatusLine as err :
58
- err_msg = "Unable to connect to the target URL or proxy ("
59
- err_msg += str (menu .options .proxy )
60
- err_msg += ")."
61
- print (settings .print_critical_msg (err_msg ))
62
- raise SystemExit ()
63
55
except _urllib .error .HTTPError as err :
64
56
if str (err .code ) == settings .INTERNAL_SERVER_ERROR or str (err .code ) == settings .BAD_REQUEST :
65
- return False
66
- elif "Connection refused" in str (err ):
67
- err_msg = "Unable to connect to the target URL or proxy ("
68
- err_msg += str (menu .options .proxy )
69
- err_msg += ")."
70
- print (settings .print_critical_msg (err_msg ))
71
- raise SystemExit ()
57
+ return False
72
58
else :
73
- try :
74
- err_msg = str (err .args [0 ]).split ("] " )[1 ] + "."
75
- except IndexError :
76
- err_msg = str (err ).replace (": " ," (" ) + ")."
77
- print (settings .print_critical_msg (err_msg ))
78
- raise SystemExit ()
59
+ _ = False
60
+ except (_urllib .error .URLError , _http_client .BadStatusLine ) as err :
61
+ _ = False
62
+ if not _ :
63
+ err_msg = "Unable to connect to the target URL or proxy."
64
+ print (settings .print_critical_msg (err_msg ))
65
+ raise SystemExit ()
66
+
79
67
80
68
# eof
0 commit comments