Saroekin
Saroekin

Reputation: 1245

Using Proxies to Handle HTTPS Connection Requests

I'm trying to run code on a site that only accepts HTTPS connections, and am having trouble incorporating it with proxies.

I run code such as this to instantiate the proxy:

os.environ['https_proxy'] = 'http://' + proxy

And when I try to complete requests using said previously implemented proxy (I'm going through the site's API), I always get this error:

HTTPSConnectionPool(host=[ . . . ], port=443): Max retries exceeded with url: [. . .] (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fab996ef790>: Failed to establish a new connection: [Errno -2] Name or service not known',)))

The question I have is to of course how to alleviate the error, though more primarily, when a HTTPS connection is forced, what are the ways to work around it so you're not completely stopped from utilizing or maneuvering around the site (with proxies)?

Upvotes: 1

Views: 2158

Answers (1)

mhawke
mhawke

Reputation: 87064

The proxy server's host name can not be resolved to an IP address.

Either there is a problem with the proxy's host name, or there is a problem with the DNS server. If you are sure that the host is correct, try using its IP address, e.g.

proxy = '192.168.1.1:1234'
os.environ['https_proxy'] = 'http://' + proxy

If that works then the proxy is OK, but the name resolution is failing for some reason. Try using curl and see if that works, e.g.

https_proxy='https://localhost:1234' curl -v https://httpbin.org

Upvotes: 1

Related Questions