diff options
Diffstat (limited to 'Lib/urllib/request.py')
-rw-r--r-- | Lib/urllib/request.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 5ddec5f14e9..d389fa9799d 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1255,6 +1255,12 @@ class AbstractHTTPHandler(BaseHandler): raise URLError(err) else: r = h.getresponse() + # If the server does not send us a 'Connection: close' header, + # HTTPConnection assumes the socket should be left open. Manually + # mark the socket to be closed when this response object goes away. + if h.sock: + h.sock.close() + h.sock = None r.url = req.get_full_url() # This line replaces the .msg attribute of the HTTPResponse @@ -1658,7 +1664,7 @@ class URLopener: return getattr(self, name)(url) else: return getattr(self, name)(url, data) - except HTTPError: + except (HTTPError, URLError): raise except socket.error as msg: raise IOError('socket error', msg).with_traceback(sys.exc_info()[2]) |