🔧 Replaced deprecated FancyURLopener
This commit is contained in:
parent
b5218d50f6
commit
9d2c6f31db
18
update.py
18
update.py
@ -281,19 +281,21 @@ def fetch_url(src, dst):
|
|||||||
Fetch file from URL src and save it to dst.
|
Fetch file from URL src and save it to dst.
|
||||||
"""
|
"""
|
||||||
import urllib.request
|
import urllib.request
|
||||||
class URLopener(urllib.request.FancyURLopener):
|
import shutil
|
||||||
def http_error_default(self, url, fp, errcode, errmsg, headers):
|
|
||||||
sys.stderr.write("ERROR: could not fetch {0}\n".format(url))
|
|
||||||
sys.exit(-1)
|
|
||||||
|
|
||||||
dirname = os.path.dirname(dst)
|
dirname = os.path.dirname(dst)
|
||||||
if dirname != '':
|
if dirname != '':
|
||||||
if not os.path.isdir(dirname):
|
if not os.path.isdir(dirname):
|
||||||
os.makedirs(dirname)
|
os.makedirs(dirname)
|
||||||
|
|
||||||
opener = URLopener()
|
try:
|
||||||
opener.retrieve(src, dst)
|
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__':
|
if __name__ == '__main__':
|
||||||
check_for_yaml()
|
check_for_yaml()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user