From 9dc3ffe064048ac714b4ff2a033afe06132c48a9 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Wed, 18 Nov 2020 18:50:30 +0100 Subject: [PATCH] more error handling, emojis --- panxy.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/panxy.py b/panxy.py index 4aca287..75d5ad1 100644 --- a/panxy.py +++ b/panxy.py @@ -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():