S
S
sharkyyy32019-11-26 10:18:25
Python
sharkyyy3, 2019-11-26 10:18:25

How to check the proxy for validity?

I'm trying to check the proxy from the "http_proxy" list using the following code:

from colorama import Fore
import requests


http_proxy = ["87.107.18.83:8080","104.245.228.65:8080","0.0.0.1:80"]


class checker(object):

    def check(self,x):
        url='http://google.com'
        try:
            requests.get(url,proxies={'http':'http://'+x},timeout=(20.05,27), verify=False)
        except requests.exceptions.ConnectionError as e:
            print(Fore.BLUE+'ОШИБКА!!!',e)
            return e
        except requests.exceptions.ConnectTimeout as e:
            print(Fore.BLUE+'ОШИБКА!!! Connection timeout',e)
            return e
        except requests.exceptions.HTTPError as e:
            print(Fore.BLUE+'ОШИБКА!!! code',e.code)
            return e.code
        except requests.exceptions.Timeout as e:
            print(Fore.BLUE+'ОШИБКА!!! Connection Timeout!',e)
            return e
        except urllib3.exceptions.ProxySchemeUnknown as e:
            print(Fore.BLUE+'ОШИБКА!!!',e)
            return e


c = checker()
for i in http_proxy:
    if c.check(i):
        print(Fore.RED + 'Bad proxy', i)
    else:
        print(Fore.GREEN + 'Good proxy', i)

I get errors in response:
ОШИБКА!!! HTTPConnectionPool(host='87.107.18.83', port=8080): Max retries exceeded with url: http://google.com/ (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000000003FB8340>, 'Connection to 87.107.18.83 timed out. (connect timeout=20.05)'))
Bad proxy 87.107.18.83:8080
ОШИБКА!!! HTTPConnectionPool(host='104.245.228.65', port=8080): Max retries exceeded with url: http://google.com/ (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000000003FB8D90>, 'Connection to 104.245.228.65 timed out. (connect timeout=20.05)'))
Bad proxy 104.245.228.65:8080
ОШИБКА!!! HTTPConnectionPool(host='0.0.0.1', port=80): Max retries exceeded with url: http://google.com/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000000003FB8CD0>: Failed to establish a new connection: [WinError 10051] Сделана попытка выполнить операцию на сокете при отключенной сети')))
Bad proxy 0.0.0.1:80

The first two proxies from the list are valid.
If instead of http:// put https:// it will show that all proxies are valid.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zlo1, 2019-11-26
@zlo1

the first proxy is invalid, the second works fully only in the connect (tunneling) mode,
both are not anonymous (the client's ip shines) and is not available in the standard https support mode,
respectively, from http google.com redirect to https www.google.com does not work
list of live (update every 10 minutes)

L
leet7, 2019-11-29
@leet7

free.proxy-sale.com/proxy-checker
Everything is much simpler here - you set a proxy and checked it, plus there are tools like a check for the anonymity level and the presence of an address in spam databases. very useful thing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question