requests 0.13.1 not working with https and proxy

The results is too may retries. I checked the same with the "standard" urllib2 and it was working without any issues.


One possible cause of getting a `ConnectionError` with the text `Too Many Retries` is that you've incorrectly specified your proxy. Are you 100% sure your proxy code matches the example [here](https://github.com/kennethreitz/requests/blob/develop/docs/user/advanced.rst#proxies)?


import requests

proxy_host = 'http://1.2.3.4:3128'
proxies={'http':proxy_host,
         'https':proxy_host}

h = requests.get("https://www.example.com", verify=False, proxies=proxies)
print h.status_code, h.error

This is my test code. I got as output
503 None

This 503 is result from proxy host.


Hmm. Your code seems fine, but that status code is odd. 503 is Service Unavailable, which is an odd error code to report. Does your proxy assign an unusual meaning to 503 Service Unavailable? If not, are you sure your proxy allows the proxying of HTTPS traffic?

If those aren't the reasons, could you tell me what proxy you're using so I can try to test it myself?


While trying to retrieve the URL:
<A HREF="https://www.gmail.com/">https://www.gmail.com/</A>
<P>
The following error was encountered:

<UL>
<LI>
<STRONG>
Connection to 173.194.70.17 Failed
</STRONG>
</UL>

<P>
The system returned:

<PRE><I>    (13) Permission denied</I></PRE>

<P>
The remote host or network may be down.  Please try the request again.
<P>Your cache administrator is <A HREF="mailto:webmaster">webmaster</A>. 
<BR clear="all">

<HR noshade size="1px">

<ADDRESS>
Generated Fri, 22 Jun 2012 10:57:50 GMT by 1.2.3.4 (squid/2.6.STABLE6-NT)
</ADDRESS>

# 

this is the output while trying to access https://www.gmail.com
All browsers are able to access https via this proxy. The proxy is the only way out to the internet.
this is the proxy id: (squid/2.6.STABLE6-NT), if you can try it yourself.

Thanks,


So, I have a theory. It's just a theory, and it'd be great if someone who knows more about HTTPS proxies could try to back me up here (@kennethreitz, any ideas?), but here goes.

[According to the Squid wiki](http://wiki.squid-cache.org/Features/HTTPS), SSL/TLS can be tunnelled through Squid using the HTTP CONNECT method or, in some tiny subset of cases, insert itself as a man-in-the-middle in your HTTPS connection. The issue with presenting itself as a man-in-the-middle is that it'll cause browsers to alert about mismatching certificates (and it's a little unethical if the proxy is controlled by someone who isn't you).

I'd be prepared to be £5 (maybe more) that your browser is using the CONNECT verb to handle the connection, and AFAIK `requests` doesn't do that. A quick reading of `urllib3.request.RequestMethods` shows that `urllib3` [doesn't handle the CONNECT verb](https://github.com/shazow/urllib3/blob/master/urllib3/request.py#L41), which suggests that if you want the functionality you'd need to submit a pull request to `urllib3`.

**tl;dr**: `requests` can't use the only HTTPS proxying method your setup of Squid allows. Probably.


Indeed urllib2 is using CONNECT, which is missing into urllib3. I rewrote the sample from above  for gmail.com with urllib2:

send: 'CONNECT www.gmail.com:443 HTTP/1.0\r\n'
send: '\r\n'
send: 'GET / HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: www.gmail.com\r\nConnection: close\r\nUser-Agent: Python-urllib/2.7\r\n\r\n'
reply: 'HTTP/1.1 301 Moved Permanently\r\n'


Ok. In this case, this isn't a bug, but a feature that has not been implemented in `urllib3`. The good news is that [there is active development in `urllib3` on improved support for proxies](https://github.com/shazow/urllib3/pull/68), which according to my reading should help with this issue a great deal. Until then, the easiest thing to do is probably continuing to use `urllib2`. Sorry!


Ok, thanks for the help!

Take care,
Bogomil