I generate sas and can access to file but when i pass url to blob client to upload_file_url it trow exception
try:
#getting container client
blob_container_client = BlobServiceClient(account_url,account_key).get_container_client(container=container_name)
#generate sas tocket for block container
sas=(BlobSharedAccessSignature(account_name, account_key).\
generate_container(container_name,permission='r',start='2021-03-01T00:00Z',expiry='2021-04-01T00:00Z'))
#generate final url with sas
final_source_url=(blob_container_client.url+'/'+sourcefile+'?'+sas)
print(final_source_url)
blob_client1=blob_container_client.get_blob_client(sourcefile)
source=blob_client1.download_blob().readall()
#---------ACCOUNT 2---------------------
# getting container client for second account
blob_client2 = BlobServiceClient(account_url2, account_key2).get_blob_client(container=container_name2,blob=destinationfile2)
blob_client2.upload_blob_from_url(final_source_url)
except Exception as ex: print('Exception:') print(ex)
Exception:
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:527a4df5-501e-003e-03d6-0f4d5b000000
Time:2021-03-03T02:41:38.6605824Z
ErrorCode:AuthenticationFailed
Error:None
AuthenticationErrorDetail:The MAC signature found in the HTTP request 'xxxxxxxxxxxxxxxxxxxxxxxxxxx=' is not the same as any computed signature. Server used following string to sign: 'PUT
x-ms-client-request-id:f9918e5a-7bc9-11eb-86ab-803049852acd
x-ms-copy-source:://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x-ms-date:Wed, 03 Mar 2021 02:41:37 GMT
x-ms-version:2020-06-12
/xxxxx/xxxxxxx/testt.txt'.
SAS is for reading from account1 then account2 upload file using sas. i want copy file from account1 to account2 .
exception is in this line: blob_client2.start_copy_from_url('final_source_url')
The issue is with the permissions in your shared access signature. You're creating a shared access signature with just read (r)
permission (which is fine for reading the blob) however you're trying to perform a write operation with that shared access signature (copy operation is a write operation).
sas=(BlobSharedAccessSignature(account_name, account_key).\
generate_container(container_name,permission='r',start='2021-03-01T00:00Z',expiry='2021-04-01T00:00Z'))
Please change your signature to include write (w)
permission and you should not get this error. Something like the following:
sas=(BlobSharedAccessSignature(account_name, account_key).\
generate_container(container_name,permission='rw',start='2021-03-01T00:00Z',expiry='2021-04-01T00:00Z'))