diff --git a/Lib/urllib.py b/Lib/urllib.py index c000f1129ea..7b2f1f74258 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -326,11 +326,12 @@ class URLopener: 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 @@ class URLopener: 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: