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.
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 5325d62..35fd1f1 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1137,6 +1137,8 @@
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