Raphael Titus
Raphael Titus

Reputation: 193

Reading file from storage container with prefix "abc" and loading as json.. Errored as " 'BlobProperties' object has no attribute 'download_blob' "

Below is the code,

connection_string='DefaultEndpointsProtocol=https;AccountName=example;AccountKey='
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
container_client = blob_service_client.get_container_client("example123")
files = container_client.list_blobs(name_starts_with="ABC")
print(files)
for blob in files:
     print("\t" + blob.name)
     blobr = blob.download_blob().readall()
     print(blobr)
     tmp_data = blobr.read().decode('utf-8')
     print(tmp.data)

Error:

AttributeError: 'BlobProperties' object has no attribute 'download_blob'

Please guide on how to read the blob from storage container and load json or do further processing

Upvotes: 0

Views: 1507

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

Reputation: 30015

This is due to the list_blobs method only returns blob properties, not the blob object. So you cannot call download_blob method via blob property.

You should change your code like below in the for statement:

for blob in files:
    blob_client=blob_service_client.get_blob_client("like example123, this is your container name",blob.name)
    blobr = blob_client.download_blob().readall()

Upvotes: 1

Related Questions