more error handling, emojis

master
Felix Pankratz 4 years ago
parent 005a3d77dc
commit 9dc3ffe064

@ -1,7 +1,8 @@
#!/usr/bin/env python3
# panxy, a random proxy connector
from urllib import request, error
from urllib import request, error
import socket
import sys
target = "http://theresno.cloud/ip"
prx_api = "http://pubproxy.com/api/proxy?limit=10&http=true&format=txt"
@ -19,18 +20,25 @@ def test_proxy(prx):
proxy_handler = request.ProxyHandler({'https': 'http://' + prx + '/', 'http': 'http://' + prx + '/' })
opener = request.build_opener(proxy_handler)
try:
result = opener.open(target)
result = opener.open(target, timeout=5)
content = result.read().decode()
print(srv_string + 'ok.')
print(srv_string + 'ok. \u2705')
return True
except error.HTTPError:
print(srv_string + 'fail.')
print(srv_string + 'fail. \u274c')
return False
#except RemoteDisconnected:
# print('fail.')
except error.URLError:
print(srv_string + 'down!')
print(srv_string + 'down! \u2935')
return False
#except error.RemoteDisconnected:
# print(srv_string + 'connection fail!')
# return False
except socket.timeout:
print(srv_string + 'timeout! \u23f3')
return False
def main():

Loading…
Cancel
Save