Search code examples
pythonazureblob

Can't list all files from my container - Azure


beginner

I've been using this code for a while, always checking, and today, trying to list my blob container files, some weren't showing up. By checking in Azure Storage Explorer, I can see it and download it from there, but not from the code. It is not listed and does not generate any errors, not even in the logs. I've tried the same code on the company server and on colab, always the same scenario.

I'm using:

name_starts_with_download = "/zip/2022"
#create the BlobServiceClient object which will be used to create a container client
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
#list all containers
container_client = blob_service_client.get_container_client(container_download)
blob_list = container_client.list_blobs(name_starts_with = name_starts_with_download)
for blob in blob_list:
  print(blob.name)

Here are three files from this container, same format, almost the same properties (except names and tags and sizes, although they are all very small), but 20220805 and 20220806 cannot be downloaded, while 20220804 can.

As code response, I get this.


Solution

  • I tried to reproduce the same in my environment i am getting the list of blobs successfully please check use below code to list the blobs

    from azure.blob.storage import blobserviceclient
    connect_str="your connection string"
    comtainer_downloads="container"
    name_starts_with_download = "folder1"
    #create the BlobServiceClient object which will be used to create a container client
    blob_service_client = BlobServiceClient.from_connection_string(connect_str)
    #list all containers
    container_client = blob_service_client.get_container_client(container_download)
    blob_list = container_client.list_blobs(name_starts_with = name_starts_with_download)
    for blob in blob_list:
      print(blob.name)
    

    enter image description here

    In storage container the same listed below

    enter image description here

    As show in your screenshot some files are not listed I would recommend you can make use of creating a diagnostic setting to capture the logs for blob storage. you can able to check whether any errors occur on that particular file or determine the file actually uploaded, if not try to reupload the file. Check your SaS token has not expire, sometimes its fails to download the file in Azure Storage Blob containers if large number of files occur.