0

I am unable to copy blob(Errror : CopySourceNotVerfied) using the SAS url generated dynamically using this code which I found here How can I generate an Azure blob SAS URL in Python?

account_name = 'account'
account_key = 'key'
container_name = 'feed'
blob_name='standard_feed'

requiredSASToken = generate_blob_sas(account_name=account_name, 
                                container_name=container_name,
                                blob_name=blob_name,
                                account_key=account_key,
                                permission=BlobSasPermissions(read=True),
                                expiry=datetime.utcnow() + timedelta(hours=24))

Instead am able to copy blob when used the SAS token generated from the azure portal, I hardcoded and tested.

The Difference observed between two tokens are like below

Code generated : se=2022-09-15T17%3A47%3A06Z&sp=r&sv=2021-08-06&sr=b&sig=xxx (sr is b)

Manually Generated : sp=r&st=2022-09-14T17:13:49Z&se=2022-09-17T01:13:49Z&spr=https&sv=2021-06-08&sr=c&sig=xxxx (sr is c)

How to generate SAS token for an azure storage container? i.e the SAS token must have all required fields especially signedResource(sr) must be container(c)?

3
  • Try to download the blob using the SAS token you generated programmatically (just paste the SAS URL in a browser’s address bar). Share the error message that is shown to you there. Commented Sep 14, 2022 at 19:22
  • @GauravMantri It says BlobNotFound, The specified blob does not exist. Strange is It says the same for the one generated manually. Commented Sep 14, 2022 at 19:51
  • Can you edit your question and include the complete error message? Commented Sep 15, 2022 at 0:45

1 Answer 1

0

I tried to reproduce the same in my environment and got below results:

from  datetime  import  datetime, timedelta
from  azure.storage.blob  import  BlobClient, generate_blob_sas, BlobSasPermissions

account_name = 'your account name'
account_key = 'your account key'
container_name = 'container'
blob_name = 'pandas.json'

def  get_blob_sas(account_name,account_key, container_name, blob_name):
sas_blob = generate_blob_sas(account_name=account_name,
container_name=container_name,
blob_name=blob_name,
account_key=account_key,
permission=BlobSasPermissions(read=True),
expiry=datetime.utcnow() + timedelta(hours=1))
return  sas_blob

blob = get_blob_sas(account_name,account_key, container_name, blob_name)
print(blob)

I got similar output:

enter image description here

I added start time in generate SAS in code:

enter image description here

How to generate SAS token for an azure storage container? i.e the SAS token must have all required fields especially signedResource(sr) must be container(c)?

Output : It has all required fields for SAS:

st=2022-09-15T12%3A23%3A44Z&se=2022-09-15T13%3A23%3A44Z&sp=r&sv=2021-08-06&sr=b&sig=XXXXX

I also tested my generated SAS token with url and got below result:

enter image description here

It says BlobNotFound, The specified blob does not exist. Strange is It says the same for the one generated manually.

I seen this error in your comment please check you have given correct blob name and path. kindly check the below proper URL.

https://{storage-account}.blob.core.windows.net/{container-name}/files/{file-name}.pdf.+ SAS
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.