简体   繁体   中英

Download files (csv, excel) from azure blob storage using Python

I am trying to download the files (csv, excel) from blob storage in Python using the below code.

from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient

blob_service_client = BlobServiceClient.from_connection_string(AZURE_STORAGE_CONNECTION_STRING)
container_client = blob_service_client.get_container_client(CONTAINER_NAME)
blob_client = container_client.get_blob_client('test12345.csv')

with open("test12345.csv", "wb") as f:
    data = blob_client.download_blob()
    data.readinto(f)'''

I am able to download the files, but the downloaded files are stored in byte data. Could anyone please help. Thank you!

If I am wrong, the implementation is slightly wrong in the last line of your snippet. You could use the below code:

f.write(data.readall())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM