question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`BlobServiceClient.list_containers()` fails when using a sas token generated using `generate_account_sas`

See original GitHub issue
  • Package Name: azure-storage-blob
  • Package Version: 12.12.0b1
  • Operating System: OSX
  • Python Version: 3.9

Describe the bug

BlobServiceClient.list_containers() fails when using an account SAS token generated using generate_account_sas

To Reproduce Steps to reproduce the behavior:

If I create an account SAS token like this:

from datetime import datetime, timezone, timedelta
from azure.storage.blob import BlobServiceClient, generate_account_sas

ACCOUNT_KEY = "<< account key >>"
ACCOUNT_NAME = "<< account name >>"
start_time = datetime.now(timezone.utc) - timedelta(minutes=1)
expiry_time = datetime.now(timezone.utc) + timedelta(hours=1)
ACCOUNT_SAS_TOKEN = generate_account_sas(
    account_key=ACCOUNT_KEY,
    account_name=ACCOUNT_NAME,
    start=start_time,
    expiry=expiry_time,
    permission="rl",
    resource_types="sco",
)
BLOB_ACCOUNT_URL = "https://{account}.blob.core.windows.net/".format(
    account=ACCOUNT_NAME
)

BlobServiceClient.list_containers() fails when using the account sas token like so:

BSC = BlobServiceClient(account_url=BLOB_ACCOUNT_URL, credential=ACCOUNT_SAS_TOKEN)
container_list = BSC.list_containers()
container_list.next()
# *** azure.core.exceptions.ClientAuthenticationError: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.

Even though it works just fine with the account key:

BSC = BlobServiceClient(account_url=BLOB_ACCOUNT_URL, credential=ACCOUNT_KEY)
container_list = BSC.list_containers()
container_list.next() # no errors

Expected behavior A clear and concise description of what you expected to happen.

BlobServiceClient.list_containers() should work with an account key generated by generate_account_sas

Screenshots N/A

Additional context N/A

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jdthorpecommented, Apr 29, 2022

Looking back, I may have (re)installed the ADLS library with the --pre flag to resolve a different issue, which would explain how I got the preview version of ADLS which depended on the beta version of azure-storage-blob. Thanks.

0reactions
jalauzon-msftcommented, Apr 28, 2022

@jdthorpe, the beta version is listed as a dependency in main but was only released for the beta version of datalake. Did you happen to install the current beta version of datalake?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js failed to connect azure-blob using SAS token when ...
I can only list the data of blobs in the specific container. The blob-storage package's error message is not very clear. Here't the...
Read more >
URL(Sas) for blob access generates 403 error on Azure, but ...
The Sas is generated through a UserDelegationKey and the BlobServiceClient is authenticated with DefaultAzureCredential.
Read more >
How to Generate an Azure SAS Token to Access Storage ...
To create a token via the Azure portal, first, navigate to the storage account you'd like to access under the Settings section then...
Read more >
Generate SAS Token For Azure Blob Storage Using Managed ...
Let's create blob service client with Azure AD credentials and then create a user delegation key for the Blob service that's valid for...
Read more >
Generating Azure Blob Storage User Delegation SAS
Azure CLI. With Azure Blob Storage it's possible to generate a Shared Access Signature (SAS) with which you can allow a third party ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found