session with proxy get error

➜  ~ python --version
Python 3.5.2

requests 2.11.1

requests session with proxy raise this error:

```
Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 595, in urlopen
    chunked=chunked)
  File "/usr/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 393, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/usr/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 389, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse
    response.begin()
  File "/usr/lib/python3.5/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.5/http/client.py", line 266, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/requests/adapters.py", line 423, in send
    timeout=timeout
  File "/usr/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 640, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3.5/site-packages/requests/packages/urllib3/util/retry.py", line 287, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
requests.packages.urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='*.*.*.*', port=8123): Max retries exceeded with url: http://1212.ip138.com/ic.asp (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response',)))

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "proxy.py", line 34, in <module>
    pg = s.get(url, auth=ProxyAuth(), timeout=(5, 20))
  File "/usr/lib/python3.5/site-packages/requests/sessions.py", line 488, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python3.5/site-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.5/site-packages/requests/sessions.py", line 596, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.5/site-packages/requests/adapters.py", line 485, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPConnectionPool(host='*.*.*.*', port=8123): Max retries exceeded with url: http://1212.ip138.com/ic.asp (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response',)))

```

my code like this : 
`

```
import requests

...

proxy = {'http': 'http://%s:%s' %(url, port), 'https': 'http://%s:%s' % (url, port)}

s = requests.Session()
s.proxies.update(proxy)
s.headers.update({'Proxy-Authorization': authHeader})

resp = s.get(url,  timeout=6)
print(resp)
```


I strongly recommend you provide proxy authorization header values in the URL instead, like this:

``` python
proxy = {'http': 'http://%s:%s@%s:%s" % (username, password, url, port)'}
```

Simply adding session headers like you've done here doesn't necessarily actually send them to the proxy. This is particularly true if you're making HTTPS requests. Try removing the `Proxy-Authorization` header and doing the above instead.


@Lukasa  Actually , I can't change the proxy authorization, It's not my proxy server. For now, I use the urllib.request  instead. Is it possible this authorization work with requests? 


I'm not asking you to change the authorization itself, just where you put it in your code.


> I strongly recommend you provide proxy authorization header values in the URL instead, like this:
> 
> ```python
> proxy = {'http': 'http://%s:%s@%s:%s" % (username, password, url, port)'}
> ```
> 
> Simply adding session headers like you've done here doesn't necessarily actually send them to the proxy. This is particularly true if you're making HTTPS requests. Try removing the `Proxy-Authorization` header and doing the above instead.

Hi @Lukasa ,
I receive same error and could not resolve.What i should do to overcome this problem?
Where should i add this :  proxy = {'http': 'http://%s:%s@%s:%s" % (username, password, url, port)'}

> e should i add this : proxy = {'http': 'http://%s:%s@%s:%s" % (username, pass

You can add this in your code.