Hi guys I have an issue when using proxies in python (requests module version 2.28.1). It seems like my proxies are not being used at all, although I pass them as arguments.
Here is my function to get proxies and my quick test to check IP:
import requests
from random import randint
def getProxies():
try:
with open("proxies.txt", "r") as proxyLoader:
# With proxies
proxyDetails = proxyLoader.read().splitlines()
proxyParts = proxyDetails[randint(0, len(proxyDetails) - 1)]
if '.' not in proxyParts:
return {"http": None, 'https': None}
else:
proxyParts = proxyParts.split(":")
if len(proxyParts) == 4:
ip, port, user, passw = proxyParts[0], proxyParts[1], proxyParts[2], proxyParts[3]
formatedProxy = {
"http": "http://{}:{}@{}:{}".format(user, passw, ip, port)
}
elif len(proxyParts) == 2:
ip, port = proxyParts[0], proxyParts[1]
formatedProxy = {
"http": "http://{}:{}".format(ip, port)
}
else:
formatedProxy = {
"http": None,
"https": None
}
return formatedProxy
except (IndexError, ValueError):
# No proxies
return {"http": None, 'https': None}
proxies = getProxies()
r = requests.get('https://api.myip.com', proxies=proxies)
print(r.text, proxies)
All I get back is my local ip (which means proxies are not used). I am wondering if this issue is from my code or if it could be coming from another python package as I was using proxies on many scripts since over 2/3 years. I would love to get your help please.
I have also tried using the format like that for proxies:
{
"http": "http://{}:{}@{}:{}".format(user, passw, ip, port),
"https": "https://{}:{}@{}:{}".format(user, passw, ip, port)
}
All I get is that error :"requests.exceptions.ProxyError: HTTPSConnectionPool(host='api.myip.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Your proxy appears to only use HTTP and not HTTPS, try changing your proxy URL to be HTTP. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#https-proxy-error-http-proxy', SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1131)'))))"
source https://stackoverflow.com/questions/75062004/python-requests-module-proxies-are-not-being-used
Comments
Post a Comment