From: Kenneth Reitz Date: Tue, 11 Oct 2011 00:59:10 +0000 (-0400) Subject: urllib3 fix X-Git-Tag: v0.8.0~94^2~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e7b31af784c25b1cbc390bad60ea19f24a0c7905;p=services%2Fpython-requests.git urllib3 fix --- diff --git a/requests/packages/urllib3/connectionpool.py b/requests/packages/urllib3/connectionpool.py index 7f974df..8da425a 100644 --- a/requests/packages/urllib3/connectionpool.py +++ b/requests/packages/urllib3/connectionpool.py @@ -258,8 +258,7 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods): these headers completely replace any pool-specific headers. :param retries: - Number of retries to allow before raising - a MaxRetryError exception. + Number of retries to allow before raising a MaxRetryError exception. :param redirect: Automatically handle redirects (status codes 301, 302, 303, 307), @@ -320,16 +319,19 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods): timeout=timeout, body=body, headers=headers) + # If we're going to release the connection in ``finally:``, then + # the request doesn't need to know about the connection. Otherwise + # it will also try to release it and we'll have a double-release + # mess. + response_conn = not release_conn and conn + + # Import httplib's response into our own wrapper object response = HTTPResponse.from_httplib(httplib_response, pool=self, - connection=conn, + connection=response_conn, **response_kw) - if release_conn: - # The connection will be released manually in the ``finally:`` - response.connection = None - # else: # The connection will be put back into the pool when # ``response.release_conn()`` is called (implicitly by