Azure / azure-storage-python

Microsoft Azure Storage Library for Python
https://azure-storage.readthedocs.io
MIT License
338 stars 240 forks source link

The sasToken in copy_source_url is needed when specify requires_sync=True in copy_blob method. #604

Open imeya opened 5 years ago

imeya commented 5 years ago

I used the copy_blob method to copy blobs in the same storage account, and both of the containers are private.

If I did not specify the sasToken in the copy_source_url, then an error occured, like below:

HTTP status code=404. ErrorCode: CannotVerifyCopySource. The specified resource does not exist.

The completed code is as below:

from azure.storage.blob import BlockBlobService

accountName="xxx"
accountKey="xxx"

blobs = BlockBlobService(account_name=accountName,account_key=accountKey)

#copy_source_url
copySource="https://xxxx.blob.core.windows.net/f22/gen2.JPG"

blobs.copy_blob("dest_container","dest_blob_name",copySource,requires_sync=True)

Some other observations:

  1. if the source container is public, it works without specify sasToen
  2. if the source container is private, but remove the requires_sync=True, it can work well.

Could you please let me know if it's by design or it's a bug? I cannot find any docs about it.

duckbytes commented 5 years ago

I found this issue a few days ago. Previously the function worked fine with require_sync=True, but stopped working out of the blue. I wonder if Azure have made a change on the remote end that is tripping it up somewhere.

zezha-msft commented 5 years ago

Hi @imeya thanks for reaching out!

It's expected behavior but we should definitely improve the doc. I'll make sure the behavior is more clearly explained.

zezha-msft commented 5 years ago

Hi @theocranmore, nothing was changed, maybe your sources were public before?

zezha-msft commented 5 years ago

FYI the REST API doc is here.

imeya commented 5 years ago

@zezha-msft , thanks for looking into this issue. And why it needs the sasToken in the source_url, since both the destionation / source container are in the same storage account? can you help explain why?

zezha-msft commented 5 years ago

Hi @imeya, it was the service's decision to make it that way, my guess is that unlike its asynchronous counterpart, synchronous copy also supports external sources (that are outside of Azure), it's simpler to always require authentication on the source so that the logics are simpler in general and easier to communicate.