正在从前缀为“abc”的存储容器中读取文件并作为json加载。。错误为“'BlobProperties'对象没有属性'download\u blob'”

2024-09-29 23:21:07 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是代码

connection_string='DefaultEndpointsProtocol=https;AccountName=example;AccountKey='
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
container_client = blob_service_client.get_container_client("example123")
files = container_client.list_blobs(name_starts_with="ABC")
print(files)
for blob in files:
     print("\t" + blob.name)
     blobr = blob.download_blob().readall()
     print(blobr)
     tmp_data = blobr.read().decode('utf-8')
     print(tmp.data)

错误:

AttributeError: 'BlobProperties' object has no attribute 'download_blob'

请指导如何从存储容器读取blob并加载json或进行进一步处理


Tags: 代码nameclientdatastringdownloadcontainerservice
1条回答
网友
1楼 · 发布于 2024-09-29 23:21:07

这是因为list_blobs方法只返回blob属性,而不返回blob对象。所以不能通过blob属性调用download_blob方法

您应该在for语句中更改代码,如下所示:

for blob in files:
    blob_client=blob_service_client.get_blob_client("like example123, this is your container name",blob.name)
    blobr = blob_client.download_blob().readall()

相关问题 更多 >

    热门问题