From 1f655deeb82be3af1fc53c2a8219dfcf1af75ba1 Mon Sep 17 00:00:00 2001 From: Lukas Date: Sat, 31 Oct 2020 20:52:29 +0100 Subject: [PATCH] Working proxy test --- src/proxy.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/proxy.py b/src/proxy.py index 44c44d9..c4aefd8 100644 --- a/src/proxy.py +++ b/src/proxy.py @@ -1,18 +1,23 @@ import requests - +from requests.auth import HTTPProxyAuth def test(proxy): - print(f'http://{proxy.usr}:{proxy.pwd}@{proxy.url}:{proxy.port}') + # print(f'http://{proxy.usr}:{proxy.pwd}@{proxy.url}:{proxy.port}') + + s = requests.Session() + url = "http://example.com" + proxies = { + 'http': f'http://{proxy.url}:{proxy.port}', + 'https': f'http://{proxy.url}:{proxy.port}' + } + auth = HTTPProxyAuth(proxy.usr, proxy.pwd) + + s.proxies = proxies + s.auth = auth try: - r = requests.get( - "http://example.com", - proxies={ - 'http': f'http://{proxy.usr}:{proxy.pwd}@{proxy.url}:{proxy.port}', - 'https': f'http://{proxy.usr}:{proxy.pwd}@{proxy.url}:{proxy.port}' - } - ) + r = s.get(url) if r.status_code == 200: proxy.isworking = True