1616else :
1717 import subprocess
1818
19- from six .moves .urllib import request
19+ from six .moves .urllib import request , error
2020
2121def to_bool (value ):
2222 x = str (value ).lower ()
@@ -209,12 +209,6 @@ def symlink_to(src, dst_dir):
209209 os .symlink (src , target )
210210 return target
211211
212- class CGetURLOpener (request .FancyURLopener ):
213- def http_error_default (self , url , fp , errcode , errmsg , headers ):
214- if errcode >= 400 :
215- raise BuildError ("Download failed with error {0} for: {1}" .format (errcode , url ))
216- return request .FancyURLopener .http_error_default (self , url , fp , errcode , errmsg , headers )
217-
218212def download_to (url , download_dir , insecure = False ):
219213 name = url .split ('/' )[- 1 ]
220214 file = os .path .join (download_dir , name )
@@ -229,7 +223,12 @@ def hook(count, block_size, total_size):
229223 bar .update (0 )
230224 context = None
231225 if insecure : context = ssl ._create_unverified_context ()
232- CGetURLOpener (context = context ).retrieve (url , filename = file , reporthook = hook , data = None )
226+ try :
227+ request .urlretrieve (url , filename = file , reporthook = hook , data = None )
228+ except error .HTTPError as e :
229+ if e .status >= 400 :
230+ raise BuildError ("Download failed with error {0} for: {1}" .format (e .status , url ))
231+ raise
233232 bar .update (bar_len )
234233 if not os .path .exists (file ):
235234 raise BuildError ("Download failed for: {0}" .format (url ))
0 commit comments