I'm having trouble with using a Proxy Dictionary with the requests library. I am using a virtual environment and testing it all out and trying to reach httpbin.org/ip. I'm getting this error:
requests.exceptions.ProxyError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /ip (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',)))
Here is my code:
import cgitb
import json
import requests
print ("Content-Type: text/html;charset=utf-8\n\n")
url = 'https://httpbin.org/ip'
proxyDict = {
'http' : 'http://123.234.250.000:8800',
'https' : 'https://123.234.250.000:8800',
}
print(proxyDict)
s = requests.Session()
response = s.get(url,proxies=proxyDict)
print(response.text)
(I replaced the IP's with fake IP's in this post)
When I remove the https part from the dictionary, I works, but uses my computer's IP address. What am I doing wrong?
UPDATE: The dictionary was correct, but the issue was the port and a firewall setup that was on my hosting server. I added the port number to the outgoing ports and it worked perfectly after that. So if you're having issues too with your Proxy Dictionary, check the ports you are using to make sure it's not a firewall issue.