enter image description hereThe Error is as shown in the image
Asked
Active
Viewed 294 times
2 Answers
2
I followed the below Steps to download the file from the blob storage to local path
- I tried your code and got the same as yours
Adding input to @MingJie-MSFT
Create an Azure Storage account, Container and Upload the file
- In visual studio code enter the below code, give your bloburl and file name.
from fileinput import filename
from azure.storage.blob import BlobServiceClient
from azure.storage.blob import BlobClient
blob_url = "your blob url"
file_name = "hello2.log"
blob_client= BlobClient.from_blob_url(blob_url)
with open(file_name, "wb") as my_blob:
download_stream= blob_client.download_blob()
my_blob.write(download_stream.readall())
- Run the code

Sampath
- 810
- 2
- 2
- 13
-
Hello Sampath and Mingjie, Thank you for responding. Can any of you tell me how to work this code while having a SAS URL, blob and container name, file name and a azure.storage.blog._shared_access_signature to connect it and be able to access the log file stored in it. I don't have access to the azure account, it is a task given to me by my superior, i have to do it with the SAS url shared with me – Prerna Chadha Feb 15 '23 at 07:55
-
you need to have Azure account, then you can follow the below image for SAS url. [Img1] https://i.imgur.com/oCBkvhj.png [Img2] https://i.imgur.com/lDShvl2.png – Sampath Feb 15 '23 at 08:23
-
Are you sure sir that i need to have an Azure account access because I am specifically being told to access the files through the SAS url shared with me without credentials, and connect that in python with blob and container name and file name given to me. I just want clarity, (not doubting your guidance) – Prerna Chadha Feb 15 '23 at 09:37
-
if you want to create an Azure storage account then you need to have the Azure account, if you have an existed SAS URL then you can use it in the code. – Sampath Feb 15 '23 at 09:55
-
Sir i have been given a SAS URL but I am not able to understand how to go about it, I've tried different approaches to connect it to the existing storage whose SAS URl has been provided to me but it is not working. Any code you can help me with? I also have blob name and container name with me and the particular file name i am asked to access – Prerna Chadha Feb 15 '23 at 10:06
-
Make sure pick the correct SAS URL from our container and add it in the above code which I provided. It worked for me! – Sampath Feb 15 '23 at 10:23
-
Sir, please check the code once in the image i am posting in the edited question above. I was advised to do something with the from azure.storage.blob._shared_access_signature command and i dont know how to go about it. – Prerna Chadha Feb 15 '23 at 10:36
-
You can find the SAS URL in this [screenshot](https://i.imgur.com/jKl89O2.png). – Sampath Feb 15 '23 at 11:24
0
The package you imported is incorrect.
The method from_blob_url
belong to package BlobClient instead of BlobServiceClient.
from azure.storage.blob import BlobClient
BlobClient.from_blob_url

MingJie-MSFT
- 5,569
- 1
- 2
- 13