diff options
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/test/test_urllib2.py | 3 | ||||
| -rw-r--r-- | Lib/urllib/request.py | 2 |
2 files changed, 5 insertions, 0 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index e9fb2fc271..58ef83611d 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -317,6 +317,9 @@ class MockHTTPClass: def getresponse(self): return MockHTTPResponse(MockFile(), {}, 200, "OK") + def close(self): + pass + class MockHandler: # useful for testing handler machinery # see add_ordered_mock_handlers() docstring diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 5325d62c40..35fd1f136f 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -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 |
