diff --git a/Lib/urllib.py b/Lib/urllib.py index c000f1129eae..7b2f1f742588 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -326,11 +326,12 @@ def open_http(self, url, data=None): if data is not None: h.send(data) errcode, errmsg, headers = h.getreply() + fp = h.getfile() if errcode == -1: + if fp: fp.close() # something went wrong with the HTTP status line raise IOError, ('http protocol error', 0, 'got a bad status line', None) - fp = h.getfile() if errcode == 200: return addinfourl(fp, headers, "http:" + url) else: @@ -417,11 +418,12 @@ def open_https(self, url, data=None): if data is not None: h.send(data) errcode, errmsg, headers = h.getreply() + fp = h.getfile() if errcode == -1: + if fp: fp.close() # something went wrong with the HTTP status line raise IOError, ('http protocol error', 0, 'got a bad status line', None) - fp = h.getfile() if errcode == 200: return addinfourl(fp, headers, "https:" + url) else: