diff -r c46ecdbd217d Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py Fri May 20 20:27:54 2011 +0300 +++ b/Lib/test/test_urllib2.py Sat May 21 15:31:33 2011 +0300 @@ -318,6 +318,9 @@ 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 -r c46ecdbd217d Lib/urllib/request.py --- a/Lib/urllib/request.py Fri May 20 20:27:54 2011 +0300 +++ b/Lib/urllib/request.py Sat May 21 15:31:33 2011 +0300 @@ -1146,6 +1146,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