Reputation: 379
I am currently working on a program where when I run it, it will do a blob data transfer from my VM to my azure storage using SAS. The code I have written so far is this:
import subprocess
import os
import sys
try:
key = input("Please insert SAS: ")
#file_path = input("Please insert the full file path where the data is located: ")
full_link = ("\"https://myblob.blob.core.windows.net/" + key + "\"")
#print('\n File path: '+ full_link +'\n')
#Subprocess that performs data transfer to storage from the desired path
subprocess.call(['azcopy', 'cp', '/directory/subdirectory',
full_link,
'--recursive=true'], stderr=subprocess.STDOUT)
print('Transfer Complete.')
#Exception for exit error
except subprocess.CalledProcessError as e:
raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
#Exception for EOF error, would be caused by missing token
except EOFError as error:
print('Error with token')
#When an unexpected error has occured.
except Exception as e:
print(str(e) + 'Unknown error has occured')
exit(0)
When I run this I receive the following error:
failed to parse user input due to error: the inferred source/destination combination is currently not supported.
I am unsure as to what the issue is because when I run the actual command in the terminal and it does the data copy that I wanted. The command is below:
sudo ./azcopy cp "/directory/subdirectory" "https://myblob.blob.core.windows.net/darknet-index[SAS]" --recursive=true
Any help is appreciated.
Upvotes: 2
Views: 7320
Reputation: 29940
You're missing blob container name in the full link.
Here is my code running on windows, you can change it to run on linux:
import subprocess
import os
import sys
try:
#sas token
key = '?sv=2019-02-02&xx'
#define the container name in blob storage
mycontainer = "test6"
exepath = "F:\\azcopy\\latest\\azcopy.exe"
local_directory="F:\\temp\\1\\test2\\*"
endpoint="https://xxx.blob.core.windows.net/"+mycontainer
myscript=exepath + " cp " + "\""+ local_directory + "\" " + "\""+endpoint + key + "\"" + " --recursive"
print(myscript)
subprocess.call(myscript)
print('Transfer Complete.')
#Exception for exit error
except subprocess.CalledProcessError as e:
raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
#Exception for EOF error, would be caused by missing token
except EOFError as error:
print('Error with token')
#When an unexpected error has occured.
except Exception as e:
print(str(e) + 'Unknown error has occured')
exit(0)
The test result:
Upvotes: 1
Reputation: 643
Maybe it can't resolve /directory/subdirectory to a real disk location, due to the working directory being different when you run it from within your Python app.
Upvotes: 0