From 9d2c6f31dbce66e3e788c534ebf0eb0d31a38296 Mon Sep 17 00:00:00 2001 From: Edgar Date: Mon, 24 Oct 2022 15:52:56 +0200 Subject: [PATCH] :wrench: Replaced deprecated FancyURLopener --- update.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/update.py b/update.py index 11978e6..fe12e44 100644 --- a/update.py +++ b/update.py @@ -281,19 +281,21 @@ def fetch_url(src, dst): Fetch file from URL src and save it to dst. """ import urllib.request - class URLopener(urllib.request.FancyURLopener): - def http_error_default(self, url, fp, errcode, errmsg, headers): - sys.stderr.write("ERROR: could not fetch {0}\n".format(url)) - sys.exit(-1) - + import shutil dirname = os.path.dirname(dst) if dirname != '': if not os.path.isdir(dirname): os.makedirs(dirname) - opener = URLopener() - opener.retrieve(src, dst) - + try: + with urllib.request.urlopen(src) as response, open(dst, 'wb') as out_file: + shutil.copyfileobj(response, out_file) + except urllib.error.HTTPError as e: + sys.stderr.write(f"\n\nERROR: could not fetch {src}, request failed with error {e.code} \n\t {e.reason}\n") + sys.exit(-1) + except urllib.error.URLError as e: + sys.stderr.write(f"\n\nERROR: could not fetch {src}, {e.reason}\n") + sys.exit(-1) if __name__ == '__main__': check_for_yaml()