From 1299a8f3b25a543c79f79e6edaebb033018029ca Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Wed, 27 Jul 2011 08:05:58 +0800 Subject: Fix closes Issue12576 - fix urlopen behavior on sites which do not send (or obsfuscates) Connection: Close header. --- Lib/urllib/request.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'Lib/urllib/request.py') diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index a09a35348c..534408d815 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1134,11 +1134,14 @@ class AbstractHTTPHandler(BaseHandler): try: h.request(req.get_method(), req.selector, req.data, headers) - r = h.getresponse() # an HTTPResponse instance - except socket.error as err: + except socket.error as err: # timeout error raise URLError(err) finally: - h.close() + try: + r = h.getresponse() # an HTTPResponse instance + except Exception as exp: + h.close() + raise exp r.url = req.get_full_url() # This line replaces the .msg attribute of the HTTPResponse -- cgit v1.2.1 From 45686b472bf1f9e5ce1ef6953c4b123d271b2dc7 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Wed, 27 Jul 2011 09:31:03 +0800 Subject: Correcting issue 12576 fix, which resulted in buildbot failures. --- Lib/urllib/request.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'Lib/urllib/request.py') diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 534408d815..1dda966a23 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1135,13 +1135,10 @@ class AbstractHTTPHandler(BaseHandler): try: h.request(req.get_method(), req.selector, req.data, headers) except socket.error as err: # timeout error + h.close() raise URLError(err) - finally: - try: - r = h.getresponse() # an HTTPResponse instance - except Exception as exp: - h.close() - raise exp + else: + r = h.getresponse() r.url = req.get_full_url() # This line replaces the .msg attribute of the HTTPResponse -- cgit v1.2.1