OSError Tunnel connection failed: 400 Bad Request

Hi, I'm  using Requests version 2.14.1, but I'm having problem with HTTPS request when using proxies.(works fine with http url)  *My proxies are already ip authorized.* I'm novice to programming so I cant exactly figure out what I'm doing wrong.

```python
import requests, random, time
proxies_list = [
    '104.153.xx.xxx:xxxx',
    '104.153.xx.xxx:xxxx'
]
while True:
    try:
        r = requests.get('https://icanhazip.com', proxies={'https': 'http://{}'.format(random.choice(proxies_list))})
        print (r.text), time.sleep(0.5)
    except Exception as e:
        print(e)
```


Can you give us more information about your system and the actual exception traceback? It'd be helpful to know exactly which OSError you're receiving.

sorry, here is the trackback. and im using Mac OSX

```
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 594, in urlopen
    self._prepare_proxy(conn)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 810, in _prepare_proxy
    conn.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 294, in connect
    self._tunnel()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 832, in _tunnel
    message.strip()))
OSError: Tunnel connection failed: 400 Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/adapters.py", line 438, in send
    timeout=timeout
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 649, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/packages/urllib3/util/retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='icanhazip.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 400 Bad Request',)))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/edwardbiswas/Desktop/Script/proxy.py", line 107, in <module>
    r = requests.get('https://icanhazip.com', proxies={'https': 'http://{}'.format(random.choice(proxies_list))})
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/sessions.py", line 518, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/sessions.py", line 639, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/adapters.py", line 500, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='icanhazip.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 400 Bad Request',)))
```

So this is the proxy saying that it doesn't like the tunnel request. In a situation like this, if you get a `requests.exceptions.ProxyError`, you should consider sleeping and then retrying. You may even want to remove the proxy that fired the error from your list of proxies for some time, as it clearly doesn't like you using it very much.

All of my 100 proxies returning same error. I also added 5sec sleep, but still giving me this issue. However these proxies working fine when I change the link to http.

>r = requests.get('http://icanhazip.com', proxies={'http': random.choice(proxies_list)}

So I really don't understand why it wont work with https.

@eviled23 That suggests that your proxies don't like the CONNECT verb. This is quite possible: you may not be able to tunnel HTTPS through your proxies.

I just tested the proxies on my chrome browser with extension and they were able to connect fine with https url. Perhaps requests has problem with reverse backconnect proxies?

Not as far as I know. Are you interested in trying to use Wireshark or tcpdump to compare what Requests is doing with what Chrome is doing?

yea sure. 

I think it's issue with rotate proxies because I just tried https requests with non rotate proxies, and it seem to be working fine.

This issue has stalled. I'm going to close this. If there is anything for Requests to do, feel free to let us know and we can reopen this.

hi, i have a big problem with proxy rotation. I have few bot for parse a web site and proxyHandler class doesen't work. Proxy are tested, and i don't have response from the web site that i'm trying to connect using proxies.
 __need help__