我正在尝试通过python中的azure.blob.storage文件访问azure上存储帐户中blob容器内的blob文件。有Blob容器,其公共访问权限级别设置为“私有”,“ blob”和“容器”
我已经通过具有所有权限的azure门户为存储帐户创建了SAS令牌。从python代码中,我能够以“容器”访问级别访问blob容器中的文件。但是,我无法访问“ blob”和“ private”级别的容器
from datetime import datetime, timedelta
def test_check_blob_containers():
account_name = ''
account_key = ''
container_name = ''
#sas_token = get_sas_token(account_name, account_key, container_name)
# I have used the sas token generated through get_sas_token as well as the one retrieved from the azure portal which was created manually.
sas_token = 'sas token retrieved from the azure portal'
block_blob_service = BlockBlobService(
account_name=account_name, sas_token=quote(sas_token))
blobs = block_blob_service.list_blobs(container_name=container_name)
for b in blobs:
print(b.name)
def get_sas_token(account_name, account_key, container_name):
blob_service = BlockBlobService(account_name=account_name, account_key=account_key)
sas_token = blob_service.generate_container_shared_access_signature(container_name, ContainerPermissions.LIST, datetime.utcnow() + timedelta(hours=1))
return sas_token
我收到以下错误:
提高前
azure.common.AzureMissingResourceHttpError:指定的资源确实
不存在。错误代码:ResourceNotFound
E ResourceNotFound
指定的资源不存在。
E RequestId:ea63a1df-001e-0003-6ffd-719913000000
E时间:2019-09-23T10:56:42.8358696Z