diff -r 12c84e740ed6 -r 8056ea19e2b2 Lib/http/client.py --- a/Lib/http/client.py Sun Mar 23 03:14:32 2014 +0000 +++ b/Lib/http/client.py Sun Mar 23 03:14:38 2014 +0000 @@ -1144,18 +1144,22 @@ else: response = self.response_class(self.sock, method=self._method) - response.begin() - assert response.will_close != _UNKNOWN - self.__state = _CS_IDLE + try: + response.begin() + assert response.will_close != _UNKNOWN + self.__state = _CS_IDLE - if response.will_close: - # this effectively passes the connection to the response - self.close() - else: - # remember this, so we can tell when it is complete - self.__response = response + if response.will_close: + # this effectively passes the connection to the response + self.close() + else: + # remember this, so we can tell when it is complete + self.__response = response - return response + return response + except: + response.close() + raise try: import ssl