我正在尝试列出 Azure 存储帐户中 Blob 容器中的 Blob。这是我的代码:
blob_service_client = BlobServiceClient.from_connection_string(landing_Access_token)
container_client = blob_service_client.get_container_client(container_name)
blob_list = container_client.list_blobs(prefix='/crm365/internal/reference/')
for i in blob_list:
print(i.name)
当我执行 for 循环来获取 blob 的每个名称时,我收到错误:
The requested URI does not represent any resource on the server
。循环之前的一切都正常。
我已经在list_blobs中传递了前缀,但它仍然是一样的 我已检查连接字符串,并且能够登录 Azure 存储并将 blob 上传到容器中。有人可以帮忙吗?
您可以使用下面的代码,使用 Python 列出具有指定前缀的 blob。
在我的环境中,我有一些具有以下结构的文件。
传送门:
from azure.storage.blob import BlobServiceClient
connection_string = "xxxxx"
container_name = "sample"
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
container_client = blob_service_client.get_container_client(container_name)
blob_list = container_client.list_blobs(name_starts_with='backup/backup2/backup3')
for i in blob_list:
print(i.name.split('/')[-1])
输出:
state_county_codes.xlsm
states_and_counties.xlsx
temp.png
temp2.jpg
参考: