squid proxy server says requests.get is  "Unsupported Request Method and Protocol" 

I am behind a squid proxy server (2.7) with authentication.  request.get (version 0.14) is rejected by squid. 

```
     r = requests.get('https://www.google.com')
     r.headers
    {'connection': 'close',
     'content-length': '1168',
     'content-type': 'text/html',
     'date': 'Thu, 04 Oct 2012 23:49:49 GMT',
     'server': 'squid/2.7.STABLE7',
     'via': '1.0 proxy_server:proxy_port (squid/2.7.STABLE7)',
     'x-cache': 'MISS from proxy_server',
     'x-cache-lookup': 'NONE from proxy_server:proxy_port',
     'x-squid-error': 'ERR_UNSUP_REQ 0'}

    r.text
    u'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head> <meta http-equiv="Content-Type"
    content="text/html; charset=utf-8"> <title>ERROR: The requested URL could not be retrieved</title> <style type="text/css"><!--   %l  body :lang(
    fa) { direction: rtl; font-size: 100%; font-family: Tahoma, Roya, sans-serif; float: right; } :lang(he) { direction: rtl; float: right; }  --><
    /style> </head><body> <div id="titles"> <h1>ERROR</h1> <h2>The requested URL could not be retrieved</h2> </div> <hr>  <div id="content"> <p>The
    following error was encountered while trying to retrieve the URL: <a href="https://www.google.com/">https://www.google.com/</a></p>  <
    blockquote id="error"> <p><b>Unsupported Request Method and Protocol</b></p> </blockquote>  <p>Squid does not support all request methods for
    all access protocols. For example, you can not POST a Gopher request.</p>  <p>Your cache administrator is <a href="mailto:webmaster%W">
    webmaster</a>.</p> <br> </div>  <hr> <div id="footer"> <p>Generated 05/Oct/2012:05:19:49 +0530 by proxy_server  (squid/2.7.STABLE7)</p> <!--
        ERR_UNSUP_REQ --> </div> </body></html> \n'
```


That's.... bizzare.

I hate proxies :)


501 error? Any idea what the issue is? Has anybody else faced something like this.  


My bad! Solved.

```
proxies = { "http": "proxy_server:proxy_port"}
r = requests.get('https://www.google.com',proxies=proxies)
```


@shoibalc I thought I saw an email about you mentioning that 'http_proxy' was the more widely used environment variable... am I hallucinating?


excellent :)


Just for future reference, this pops up on PythonAnywhere as well but for HTTPS proxies for which this workaround does not seem to work.


I still get this with requests 1.2... is there a special patch I need?

Here's a post I submitted to https://github.com/mikeal/request/issues/552

I know I've seen lots of stack overflow questions about this.  I cannot seem to figure out which version of python and which version of requests are needed to get this simple test working:

``` python
import requests.packages.urllib3 as urllib3
import unittest

class TestProxyConnect(unittest.TestCase):
    def setUp(self):
        self.proxy_url='http://192.168.201.138:3128/'
        self.https_url='https://www.google.com/index.html'
    def test_connect(self):
        proxy=urllib3.proxy_from_url(self.proxy_url)
        res=proxy.urlopen('GET', self.https_url)
        self.assertEqual(res.status, 200)

if __name__ == '__main__':
    unittest.main()
```

```
F
======================================================================
FAIL: test_connect (__main__.TestProxyConnect)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/root/test.py", line 11, in test_connect
    self.assertEqual(res.status, 200)
AssertionError: 501 != 200
```

It's just trying to use squid.  I know this is more urllib3, but I am using the urllib3 that is in the requests 'packages' folder.

(venv)[root@cb-server-test urllib3]# pip freeze
requests==1.2.0
wsgiref==0.1.2

Can anyone help me figure out how to get HTTPS requests over HTTP to use CONNECT?

Thanks,
Ben


HTTPS requests over HTTP currently cannot use CONNECT. For a fuller explanation, see #1359.