【问题标题】:Accessing csv file from blob container through Azure notebook通过 Azure 笔记本从 blob 容器访问 csv 文件
【发布时间】:2021-11-19 18:28:06
【问题描述】:

我想使用 Azure Python 笔记本从 Blob 存储中的容器访问大小约为 2GB 的文件,但由于某种原因,我遇到了这个错误。

PermissionError: [Errno 13] Permission denied: 'part-00000-tid-9128541598398997257-8ae9f3ab-ad94-4ed6-ac2d-91b488393378-72-1-c000.csv'

Here is the snippet of code that worked for me before, but for some reason is not working now

【问题讨论】:

标签: python azure-blob-storage


【解决方案1】:

我已包含存储帐户 URL,它对我有用。 这是供您参考的代码

from azure.storage.blob import BlobServiceClient
import pandas as pd

STORAGEACCOUNTNAME= "<Storage account Name>"
STORAGEACCOUNTKEY= "<Storage account key>"
LOCALFILENAME= "<Local file name>"
CONTAINERNAME= "<Container name>"
BLOBNAME= "<blob name>"
STORAGEACCOUNTURL="https://<storage account name>.blob.core.windows.net"

#To download the blob
blob_service_client_instance = BlobServiceClient(account_url=STORAGEACCOUNTURL, credential=STORAGEACCOUNTKEY)
blob_client_instance = blob_service_client_instance.get_blob_client(CONTAINERNAME, BLOBNAME, snapshot=None)
with open(LOCALFILENAME, "wb") as my_blob:
    blob_data = blob_client_instance.download_blob()
    blob_data.readinto(my_blob)

#Read the blob
dataframe_blobdata = pd.read_csv(LOCALFILENAME)
print(dataframe_blobdata)

这是输出

参考: Explore data in Azure Blob storage with pandas - Team Data Science Process - Azure Architecture Center | Microsoft Docs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-19
    • 2017-12-20
    • 1970-01-01
    • 2019-06-28
    • 2021-10-13
    • 2018-04-13
    • 1970-01-01
    • 2021-03-19
    相关资源
    最近更新 更多