Close HTTPSConnection in case of exception
@@ -857,7 +857,9 @@ class _Request(object):
except Exception as e:
raise MalformedResponseError(self.network, e)
+ try:
self._check_response_for_errors(response_text)
+ finally:
conn.close()
return response_text
