On connection refused, socket.error instead of requests.exceptions.ConnectionError

With requests==0.11.1

> > > requests.get('http://127.0.0.1')
> > > Traceback (most recent call last):
> > >   File "<stdin>", line 1, in <module>
> > >   File "/var/blah/envs/dev/lib/python2.7/site-packages/requests/api.py", line 52, in get
> > >     return request('get', url, *_kwargs)
> > >   File "/var/blah/envs/dev/lib/python2.7/site-packages/requests/api.py", line 40, in request
> > >     return s.request(method=method, url=url, *_kwargs)
> > >   File "/var/blah/envs/dev/lib/python2.7/site-packages/requests/sessions.py", line 208, in request
> > >     r.send(prefetch=prefetch)
> > >   File "/var/blah/envs/dev/lib/python2.7/site-packages/requests/models.py", line 580, in send
> > >     raise ConnectionError(e)
> > > requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=80): Max retries exceeded with url: /

With requests==0.13.5

> > > requests.get('http://127.0.0.1')
> > > Traceback (most recent call last):
> > >   File "<stdin>", line 1, in <module>
> > >   File "/var/blah/envs/dev/lib/python2.7/site-packages/requests/api.py", line 54, in get
> > >     return request('get', url, *_kwargs)
> > >   File "/var/blah/envs/dev/lib/python2.7/site-packages/requests/safe_mode.py", line 37, in wrapped
> > >     return function(method, url, *_kwargs)
> > >   File "/var/blah/envs/dev/lib/python2.7/site-packages/requests/api.py", line 42, in request
> > >     return s.request(method=method, url=url, *_kwargs)
> > >   File "/var/blah/envs/dev/lib/python2.7/site-packages/requests/sessions.py", line 230, in request
> > >     r.send(prefetch=prefetch)
> > >   File "/var/blah/envs/dev/lib/python2.7/site-packages/requests/models.py", line 603, in send
> > >     timeout=self.timeout,
> > >   File "/var/blah/envs/dev/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 415, in urlopen
> > >     body=body, headers=headers)
> > >   File "/var/blah/envs/dev/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 267, in _make_request
> > >     conn.request(method, url, *_httplib_request_kw)
> > >   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 941, in request
> > >     self._send_request(method, url, body, headers)
> > >   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 975, in _send_request
> > >     self.endheaders(body)
> > >   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 937, in endheaders
> > >     self._send_output(message_body)
> > >   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 797, in _send_output
> > >     self.send(msg)
> > >   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 759, in send
> > >     self.connect()
> > >   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 740, in connect
> > >     self.timeout, self.source_address)
> > >   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 571, in create_connection
> > >     raise err
> > > socket.error: [Errno 61] Connection refused


This was fixed a long time ago, please update :)


I'm confused, isn't 0.13.5 the latest release ?


Oh, I'm sorry, I only saw the first traceback :)


Cool! Quick git bisect seems to point to https://github.com/kennethreitz/requests/commit/e02fb2eb6c2acfa67793a2c77a3c7bd47998a024 


This was caused by a change in urllib3 which broke socket.error catching in their connection pool. I've submitted a pull request that fixes it:

https://github.com/shazow/urllib3/pull/92

This should fix the issue once the change gets into the urllib3 version bundled with requests.


#648