shazow/urllib3 — pull request #92 by PeterScott (2012-08-08 19:43:34+00:00)
Title: Bugfix for socket.error being raised from connection pool

After applying [pull request #86](https://github.com/shazow/urllib3/pull/86), any `socket.error` raised by `ConnectionPool._make_request()` will not be caught, and will instead be raised to external code. However, if we get a "Connection Refused" error, we want to deal with this the same way we deal with similar errors: retry until we hit the retry limit, then (if it's still failing) raise `MaxRetryError`.

Here's how to reproduce the bug, on your current master branch:

```
>>> import urllib3
>>> urllib3.PoolManager().request('GET', 'http://127.0.0.1')
Traceback (most recent call last):
File "", line 1, in
File "/Users/peterscott/tmp/urllib3/urllib3/request.py", line 67, in request
**urlopen_kw)
File "/Users/peterscott/tmp/urllib3/urllib3/request.py", line 80, in request_encode_url
return self.urlopen(method, url, **urlopen_kw)
File "/Users/peterscott/tmp/urllib3/urllib3/poolmanager.py", line 117, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/Users/peterscott/tmp/urllib3/urllib3/connectionpool.py", line 416, in urlopen
body=body, headers=headers)
File "/Users/peterscott/tmp/urllib3/urllib3/connectionpool.py", line 268, 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
```

After merging this pull request, the behavior becomes:

```
>>> urllib3.PoolManager().request('GET', 'http://127.0.0.1')
Traceback (most recent call last):
File "", line 1, in
File "/Users/peterscott/tmp/urllib3/urllib3/request.py", line 67, in request
**urlopen_kw)
File "/Users/peterscott/tmp/urllib3/urllib3/request.py", line 80, in request_encode_url
return self.urlopen(method, url, **urlopen_kw)
File "/Users/peterscott/tmp/urllib3/urllib3/poolmanager.py", line 117, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/Users/peterscott/tmp/urllib3/urllib3/connectionpool.py", line 482, in urlopen
release_conn=release_conn, **response_kw)
File "/Users/peterscott/tmp/urllib3/urllib3/connectionpool.py", line 482, in urlopen
release_conn=release_conn, **response_kw)
File "/Users/peterscott/tmp/urllib3/urllib3/connectionpool.py", line 482, in urlopen
release_conn=release_conn, **response_kw)
File "/Users/peterscott/tmp/urllib3/urllib3/connectionpool.py", line 482, in urlopen
release_conn=release_conn, **response_kw)
File "/Users/peterscott/tmp/urllib3/urllib3/connectionpool.py", line 391, in urlopen
raise MaxRetryError(self, url)
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=80): Max retries exceeded with url: /
```

This was breaking requests, causing [requests issue #748](https://github.com/kennethreitz/requests/issues/748).