Fix HTTP error handling

This commit is contained in:
Fierelier 2021-03-25 20:45:33 +01:00
parent 8790f85835
commit c0e330d50d
1 changed files with 2 additions and 2 deletions

View File

@ -25,7 +25,6 @@ def downloadPage(window,downloadId,url,headers = False):
try:
requestHandler = opener.open(url)
# Check whether to transfer the page to the viewer, or if to open downloader
response["headers"] = requestHandler.getheaders()
contentType, contentTypeArguments = getContentType(response["headers"],"application/octet-stream")
@ -35,8 +34,9 @@ def downloadPage(window,downloadId,url,headers = False):
response["body"] = requestHandler.read()
requestHandler.close()
except urllib.error.HTTPError as e:
response["headers"] = e.getheaders()
response["body"] = e.read()
requestHandler.close()
e.close()
except Exception as e:
response["body"] = str(e).encode("utf-8")
response["headers"] = [["content-type","text; charset=utf-8"]]