2

I am trying to download an excel file on a blob. However, it keeps generating the error "The specified blob does not exist". This error happens at blob_client.download_blob() although I can get the blob_client. Any idea why or other ways I can connect using managed identity?

default_credential = DefaultAzureCredential()
 
blob_url = BlobServiceClient('url', credential = default_credential)
   
container_client = blob_url.get_container_client('xx-xx-data')

blob_client = container_client.get_blob_client('TEST.xlsx')

downloaded_blob = blob_client.download_blob()

df=pd.read_excel(downloaded_blob.content_as_bytes(), sheet_name='Test',skiprows=2)
7
  • Can you please confirm if TEST.xlsx blob exists in it-dashboards-data blob container? Commented May 3, 2021 at 11:10
  • Yes it does. Checked it multiple times... Commented May 3, 2021 at 11:14
  • Please note that blob names are case sensitive. Blob should be exactly named TEST.xlsx. Commented May 3, 2021 at 11:20
  • Yes..I copied and pasted the name in from the blob URL Commented May 3, 2021 at 11:22
  • Is the url simple blob URL like https://account.blob.core.windows.net/container/blob or is it a SAS URL? Commented May 3, 2021 at 11:24

2 Answers 2

1

Turns out that I have to also provide 'Reader' access on top of 'Storage Blob Data Contributor' to be able to identify the blob. There was no need for SAS URL.

Sign up to request clarification or add additional context in comments.

Comments

0

The reason you're getting this error is because each request to Azure Blob Storage must be an authenticated request. Only exception to this is when you're reading (downloading) a blob from a public blob container. In all likelihood, the blob container holding this blob is having a Private ACL and since you're sending an unauthenticated request, you're getting this error.

I would recommend using a Shared Access Signature (SAS) URL for the blob with Read permission instead of simple blob URL. Since a SAS URL has authorization information embedded in the URL itself (sig portion), you should be able to download the blob provided SAS is valid and has not expired.

Please see this for more information on Shared Access Signature: https://learn.microsoft.com/en-us/rest/api/storageservices/delegate-access-with-shared-access-signature.

3 Comments

Is there a way to create SAS URL using DefaultAzureCredential()? I have to just download a blob using managed identity. I'd read through the link and can't seem to get it working.
Can you confirm if managed identity is working for you? Are you running the code in Azure or locally?
Yes it’s working correctly. I’m already using managed identity for authenticating with SQL. Just that I’m having issues with storage blob. I’m testing locally and in Azure, both seems to have issues

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.