Search code examples
pythonazure-blob-storageazure-storageazure-python-sdk

azure copy blobs across storage accounts fails with ErrorCode:CannotVerifyCopySource


I am using python sdk to copy blobs from one container to another, Here is the code,

from azure.storage.blob import BlobServiceClient

src_blob = '{0}/{1}'.format(src_url,blob_name)
destination_client = BlobServiceClient.from_connection_string(connectionstring)
copied_blob = destination_client.get_blob_client(dst_container,b_name)
copied_blob.start_copy_from_url(src_blob)

It throws the below error,

 Content: <?xml version="1.0" encoding="utf-8"?><Error><Code>CannotVerifyCopySource</Code><Message>Public access is not permitted on this storage account.

I already gone through this post here and in my case the public access is disabled enter image description here.

I do not have sufficient privilege to enable public access on the storage and test? Is there a work around solution to accomplish copy without changing that setting?

Azcopy 409 Public access is not permitted on this storage account

Do I need to change the way I connect to the account?


Solution

  • When copying a blob across storage accounts, the source blob must be publicly accessible so that Azure Storage Service can access the source blob. You were getting the error because you were using just the blob's URL. If the blob is in a private blob container, Azure Storage Service won't be able to access the blob using just its URL.

    To fix this issue, you would need to generate a SAS token on the source blob with at least Read permission and use that SAS URL as copy source.

    So your code would be something like:

    src_blob_sas_token = generate_sas_token_somehow()
    src_blob = '{0}/{1}?{2}'.format(src_url,blob_name, src_blob_sas_token)