Issue #12133: fix a ResourceWarning in urllib.request

AbstractHTTPHandler.do_open() of urllib.request closes the HTTP connection if
its getresponse() method fails with a socket error. Patch written by Ezio
Melotti.
This commit is contained in:
Victor Stinner 2011-06-17 14:01:18 +02:00
parent 0f83b1511c
commit a4c45d73cf
3 changed files with 9 additions and 0 deletions

View file

@ -1137,6 +1137,8 @@ class AbstractHTTPHandler(BaseHandler):
r = h.getresponse() # an HTTPResponse instance
except socket.error as err:
raise URLError(err)
finally:
h.close()
r.url = req.get_full_url()
# This line replaces the .msg attribute of the HTTPResponse