Working proxy test

This commit is contained in:
Lukas 2020-10-31 20:52:29 +01:00
parent e6952a8025
commit 1f655deeb8
1 changed files with 14 additions and 9 deletions

View File

@ -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