Пытаюсь проверить прокси из списка "http_proxy" использую следующий код:
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)
Получаю ошибки в ответ:
ОШИБКА!!! 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
Первые два прокси из списка валидные.
Если вместо http:// поставить https:// покажет что все прокси валидные.