I am trying to download a file from a container in a Blob Storage account.
In my python script I am first creating a sas token and then trying to use this to download the file
from datetime import datetime, timedelta
from urllib.request import urlretrieve
from azure.storage.blob import (
BlockBlobService,
BlobPermissions
)
accountName ="myaccountName"
accountKey = "myaccountKey"
containerName = "mycontainerName"
blob_name = "test.txt"
local_path = "testlocal.txt"
service = BlockBlobService(account_name=accountName, account_key=accountKey)
permission = BlobPermissions(_str="racwd")
sas = service.generate_blob_shared_access_signature(containerName, 'test.txt', permission, datetime.utcnow() + timedelta(hours=1),)
sas_service = BlockBlobService(
account_name=accountName,
sas_token= sas
)
blob_uri = "https://myaccountName.blob.core.windows.net/" + containerName + "/" + blob_name +"?"+ sas
print (sas)
print(blob_uri)
urlretrieve(blob_uri, local_path)
Running this produces the error
HTTPError: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
Does anyone know how I can create a sas token that gives download access to one specific file in my container?