0

I have been testing a site with a social media login validation. It's quite primitive aside from that I built in the ability to connect through a proxy. This works fine, including the proxy, when I run it from my box or the server the site is on. However, once I enabled https/ssl on my server and used the proxy, it stopped working with this error:

 File "myprogram.py", line 274, in login
 r = self.s.get(self.url)
 File "/usr/lib/python2.6/site-packages/requests/sessions.py", line 476, in get
 return self.request('GET', url, **kwargs)
 File "/usr/lib/python2.6/site-packages/requests/sessions.py", line 464, in request
 resp = self.send(prep, **send_kwargs)
 File "/usr/lib/python2.6/site-packages/requests/sessions.py", line 576, in send
 r = adapter.send(request, **kwargs)
 File "/usr/lib/python2.6/site-packages/requests/adapters.py", line 424, in send
 raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='socialmediawebsite', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', error(111, 'Connection refused')))

I've read a solid amount and have looked through the code for requests and urllib3, but it seems more and more like I have a fundamental misunderstanding. I've tried HTTPAuth, setting verify to False, and setting environment variables. I have also tried without the proxy, and it works, which has added to my confusion. It seems to me like there might be another piece of technology required to send this https request through the proxy. Or is it just that I have to open up more ports somewhere or something equally simple?

There is one question similar to mine here: Python Requests doesnt work for https proxy

But the accepted answer is factually inaccurate and didn't work for me.

What my code looks like:

proxies = {
 'http': 'http://user:[email protected]:3128',
 'https': 'http://user:[email protected]:3128',
}
self.s.update(proxies)
self.s.get(self.url)
asked Aug 27, 2017 at 23:21
10
  • What part of 'connection refused' don't you understand? Commented Aug 28, 2017 at 1:18
  • I don't understand why this only occurs when using a proxy with ssl, or how to approach fixing it. Commented Aug 28, 2017 at 2:12
  • @aJetHorn: Unfortunately you don't show any code on how to use the proxy with SSL compared to how to use it without SSL. But what the message clearly says is that the TCP connection is refused by the proxy. This is before you even have authenticate. Given that proxy with HTTP works you might have the wrong proxy setting for HTTPS while the correct one with HTTP. Commented Aug 28, 2017 at 4:56
  • @SteffenUllrich Thank you for your reply. My mistake on not including that code. I'm using an example from the requests documentation which I have included above. Is there something I am not understanding about HTTPS? The docs seem to suggest that just having the dict defined is enough--and I have been unable to find a resource that suggests otherwise Commented Aug 28, 2017 at 19:40
  • @aJetHorn: the documentation does not say that the existence of the variable proxies is sufficient. Instead the example code provided is this: requests.get('http://example.org', proxies=proxies) which explicitly sets the proxies for the request. BTW, I have no idea what self.s in your code is and what self.s.update does. Commented Aug 28, 2017 at 19:59

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.