0
votes

I am trying to access the blob files within a blob container in a storage account on azure via azure.blob.storage file in python. There are blob containers with public access level set as "private" , "blob" and "container"

I have created a SAS Token for the storage account through the azure portal with all permissions. From python code, I am able to access the files in a blob container with "container" access level. However, I am not able to access the containers with "blob" and "private" level

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

I am getting the below error :

raise ex azure.common.AzureMissingResourceHttpError: The specified resource does not exist. ErrorCode: ResourceNotFound E ResourceNotFoundThe specified resource does not exist. E RequestId:ea63a1df-001e-0003-6ffd-719913000000 E Time:2019-09-23T10:56:42.8358696Z

1

1 Answers

0
votes

I can reproduce your issue on my side, the issue was casued by the quote(), just remove it.

enter image description here

That line should be like below.

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