@@ -60,12 +60,20 @@ def install_azcopy(self, install_location):
6060 if self .system == 'Windows' :
6161 if platform .machine ().endswith ('64' ):
6262 file_url = base_url .format ('windows' , 'amd64' , AZCOPY_VERSION , 'zip' )
63+ if _verify_url (file_url ) is None :
64+ file_url = _verify_url ('https://aka.ms/InstallAzCopyForCLIWindowsX64' )
6365 else :
6466 file_url = base_url .format ('windows' , '386' , AZCOPY_VERSION , 'zip' )
67+ if _verify_url (file_url ) is None :
68+ file_url = _verify_url ('https://aka.ms/InstallAzCopyForCLIWindows' )
6569 elif self .system == 'Linux' :
6670 file_url = base_url .format ('linux' , 'amd64' , AZCOPY_VERSION , 'tar.gz' )
71+ if _verify_url (file_url ) is None :
72+ file_url = _verify_url ('https://aka.ms/InstallAzCopyForCLILinux' )
6773 elif self .system == 'Darwin' :
6874 file_url = base_url .format ('darwin' , 'amd64' , AZCOPY_VERSION , 'zip' )
75+ if _verify_url (file_url ) is None :
76+ file_url = _verify_url ('https://aka.ms/InstallAzCopyForCLIDarwin' )
6977 else :
7078 raise CLIError ('Azcopy ({}) does not exist.' .format (self .system ))
7179 try :
@@ -74,8 +82,10 @@ def install_azcopy(self, install_location):
7482 os .chmod (install_location ,
7583 os .stat (install_location ).st_mode | stat .S_IXUSR | stat .S_IXGRP | stat .S_IXOTH )
7684 except OSError as err :
85+ azcopy_install_guide = 'https://learn.microsoft.com/azure/storage/common/storage-use-azcopy-v10'
7786 raise CLIError ('Connection error while attempting to download azcopy {}. You could also install the '
78- 'specified azcopy version to {} manually. ({})' .format (AZCOPY_VERSION , install_dir , err ))
87+ 'specified azcopy version to {} manually following the guide here: {} '
88+ '({})' .format (AZCOPY_VERSION , install_dir , azcopy_install_guide , err ))
7989
8090 def check_version (self ):
8191 try :
@@ -218,6 +228,7 @@ def _get_default_install_location():
218228
219229def _urlretrieve (url , install_location ):
220230 import io
231+ logger .warning ('Downloading AzCopy from %s' , url )
221232 req = urlopen (url )
222233 compressedFile = io .BytesIO (req .read ())
223234 if url .endswith ('zip' ):
@@ -235,3 +246,15 @@ def _urlretrieve(url, install_location):
235246 f .write (tar .extractfile (tarinfo ).read ())
236247 else :
237248 raise CLIError ('Invalid downloading url {}' .format (url ))
249+
250+
251+ def _verify_url (url ):
252+ from urllib .error import HTTPError , URLError
253+ try :
254+ response = urlopen (url )
255+ if response .code == 200 :
256+ return response .url
257+ return None
258+ except (HTTPError , URLError ):
259+ logger .warning ('There is an error downloading from the url: %s' , url )
260+ return None
0 commit comments