python 正在Azure中列出容器内的Blob

2w2cym1i  于 2022-12-17  发布在  Python
关注(0)|答案(1)|浏览(156)

我可以使用python从azure blob存储中下载单个文件:

from azure.storage.blob import BlobClient, ContainerClient
import pandas as pd
from io import StringIO
sas_url = 'https://tenant_datalake.blob.core.windows.net/filename.xml?sp=racwdymeop&st=2022-12-16T14:24:34Z&se=2022-12-16T22:24:34Z&sv=2021-06-08&sr=b&sig=xxxxx'
blob_client = BlobClient.from_blob_url(sas_url)
blob_data = blob_client.download_blob()
df = pd.read_csv(StringIO(blob_data.content_as_text())) # works fine

然而,当我在虚拟文件夹级别定义SAS url后尝试列出虚拟文件夹内的blob时,我得到

# container level 
container_sas_url = 'https://tenantdatalake.blob.core.windows.net/folder1/folder2?sp=racwdlmeop&st=2022-12-16T09:55:06Z&se=2022-12-16T17:55:06Z&sv=2021-06-08&sr=d&sig=xxxx&sdd=1'
container_client = ContainerClient.from_container_url(container_sas_url)
[*container_client.list_blobs('New')]

HttpResponseError: The requested URI does not represent any resource on the server.
RequestId:3e296e90-101e-00a3-4b5e-1105f9000000
Time:2022-12-16T14:57:54.6144977Z
ErrorCode:InvalidUri

欢迎任何帮助

zzlelutf

zzlelutf1#

我通过使用根文件夹容器而不是子文件夹解决了这个问题。代码本身没有任何问题。

相关问题