如何在访问私有Blob容器-python时修复“ AzureMissingResourceHttpError。ErrorCode:ResourceNotFound”?

时间:2019-09-23 13:22:32

标签: python azure azure-blob-storage

我正在尝试通过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

1 个答案:

答案 0 :(得分:0)

我可以重现您的问题,该问题是由quote()引起的,只需将其删除即可。

enter image description here

该行应如下所示。

block_blob_service = BlockBlobService(account_name=account_name, sas_token=sas_token)