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)?

Deepak Kothari
  • 1,601
  • 24
  • 31
  • 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. – Gaurav Mantri Sep 14 '22 at 19:22
  • @GauravMantri It says BlobNotFound, The specified blob does not exist. Strange is It says the same for the one generated manually. – Deepak Kothari Sep 14 '22 at 19:51
  • Can you edit your question and include the complete error message? – Gaurav Mantri Sep 15 '22 at 00:45

1 Answers1

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
Venkatesan
  • 3,748
  • 1
  • 3
  • 15