0

I'm trying to get the count if items in my container and I'm getting an error:

InvalidChunkLength(got length b'', 0 bytes read

code:

from azure.storage.blob import ContainerClient
import requests
# Set the SAS URI for your Azure Blob container
sas_uri = "*************************"

# Create a ContainerClient object using the SAS URI
container_client = ContainerClient.from_container_url(sas_uri)

# Get the count of blobs in the container
blobs_count = sum(1 for _ in container_client.list_blobs())

# Display the count of blobs
print("Number of blobs in the container:", blobs_count)

I'm thrown with this error:

Unable to stream download: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))

I don't know what to do.

toyota Supra
  • 3,181
  • 4
  • 15
  • 19

1 Answers1

0

Trying to get the count if items in my container

You can use the below code to get the Blob count with Container sas URI using Python.

Code:

from azure.storage.blob import ContainerClient

sas_uri="your container sas uri"
container_client = ContainerClient.from_container_url(sas_uri)
blobs=container_client.list_blobs()

number = 0
size = 0
for blob in blobs:
    number += 1
    print(blob.name)

print("Number of blobs in the container:", number)

Output:

19-06-2023.html
20-06-2023 (1).html
20-06-2023.html
21-06-2023 (1).html
21-06-2023.html
demo.pdf
demo.xls
file_last_dates.rds
Number of blobs in the container: 8

enter image description here

Venkatesan
  • 3,748
  • 1
  • 3
  • 15