gpt4 book ai didi

python - “BlobServiceClient”对象没有属性 'ls_files'

转载 作者:行者123 更新时间:2023-12-03 00:40:53 26 4
gpt4 key购买 nike

我正在尝试使用此 github ( https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/storage/azure-storage-blob/samples/blob_samples_directory_interface.py ) 中找到的 BlobServiceClient 库中的 ls_files 函数。但是,当我运行代码时,出现错误:

“BlobServiceClient”对象没有属性“ls_files”

这是我的代码:

import os, uuid, sys
from azure.storage.blob import BlobClient, BlobServiceClient, ContainerClient, PublicAccess, __version__
from azure.storage.blob.blockblobservice import BlockBlobService
import re

account_name = ACCOUNT_NAME
account_key = ACCOUNT_KEY
connect_str = CONNECTION_STRING
account_url = ACCOUNT_URL
container_name = CONTAINER_NAME
file_path = FILE_PATH
block_blob_service = BlockBlobService(account_name = account_name, account_key = account_key)
blob_service_client = BlobServiceClient(account_url = account_url, connect_str = connect_str, container_name = container_name)

def list_filenames_in_blob(blob):
file_names = blob_service_client.ls_files(file_path)
return file_names

def run_action():
try:
for blob in generator:
list_filenames_in_blob(blob)
except Exception as e:
print(e)

# Main method.
if __name__ == '__main__':
run_action()

你能告诉我我做错了什么吗?预先非常感谢您。

最佳答案

python包中的类BlobServiceClient没有方法ls_files。更多详情请引用here 。我们需要自己去实现。在文档中,您引用the user also does that .

此外,根据我的理解,我们希望在一个存储容器中列出所有 blob 的名称。如果是,请引用以下代码

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

conn_str = ''
blob_service_client = BlobServiceClient.from_connection_string(conn_str)

blob_list = blob_service_client.get_container_client('<container name>').list_blobs()

for blob in blob_list:
print(blob.name)

enter image description here

关于python - “BlobServiceClient”对象没有属性 'ls_files',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64153221/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com