0

I am using below code to copy blob across different storage accounts, but it fails with the below error

src_blob = '{0}/{1}?{2}'.format('source_url',b_name,'sp=rw&st=2022-11-17T20:44:03Z&se=2022-12-31T04:44:03Z&spr=https&sv=2021-06-08&sr=c&sig=ZXRe2FptVF5ArRM%2BKDAkLboCN%2FfaD9Mx38yZGWhnps0%3D')

            destination_client = BlobServiceClient.from_connection_string("destination_connection_string")//The connection string has sas token which has sr=c
            copied_blob = destination_client.get_blob_client('standardfeed', b_name)
            copied_blob.start_copy_from_url(src_blob)

ErrorCode: AuthorizationPermissionMismatch This request is not authorized to perform this operation using this permission.

Any thing missing or did I copy the wrong SAS token?

Deepak Kothari
  • 1,601
  • 24
  • 31
  • @Venkatesan I am already doing it using format src_blob = '{0}/{1}?{2}'.format('source_url',b_name,'sp=rw&st=2022-11-17T20:44:03Z&se=2022-12-31T04:44:03Z&spr=https&sv=2021-06-08&sr=c&sig=ZXRe2FptVF5ArRM%2BKDAkLboCN%2FfaD9Mx38yZGWhnps0%3D') – Deepak Kothari Nov 18 '22 at 07:43
  • In your source_url have you mentioned container name? – Venkatesan Nov 18 '22 at 07:53
  • Can you share what destination connection string looks like? – Gaurav Mantri Nov 18 '22 at 09:02

1 Answers1

1

I tried in my environment and successfully copied blob from one storage account to another storage account.

Code:

from  azure.storage.blob  import  BlobServiceClient

b_name="sample1.pdf"

src_blob = '{0}/{1}?{2}'.format('https://venkat123.blob.core.windows.net/test',b_name,'sp=r&st=2022-11-18T07:46:10Z&se=2022-11-18T15:46:10Z&spr=https&sv=<SAS token >)

destination_client = BlobServiceClient.from_connection_string("<connection string>")

copied_blob = destination_client.get_blob_client('test1', b_name)

copied_blob.start_copy_from_url(src_blob)

Console:

enter image description here

Portal: enter image description here

Make sure you has necessary permission for authentication purpose you need to assign roles in your storage account.

  • Storage Blob Data Contributor
  • Storage Blob Data Reader

Portal:

enter image description here

Update:

You can get the connection string through portal:

enter image description here

Reference: Azure Blob Storage "Authorization Permission Mismatch" error for get request with AD token - Stack Overflow

Venkatesan
  • 3,748
  • 1
  • 3
  • 15