2

i have issue with reading my file in blob storage. My file is only text on it.

For example I want to get from my file information My file

{......}

Ant I want get in on variable like this s = {......}

I upload in blob storage string like this.

    blob = BlobClient.from_connection_string(conn_str="DefaultEndpointsProtocol=https;AccountName=dasdasdas;AccountKey=sdf+sdfds+dfds==;EndpointSuffix=core.windows.net", container_name="XXXXXX", blob_name="XXXX.json")
    
    
    store_items = 'swx'
    data = str(store_items) + str(conversation_reference)
    blob.upload_blob(data, overwrite=True)

Now i want get what value and use it.

I try something like this

block_blob_service = BlockBlobService(account_name='XXXXX', account_key='XXXXX+XXXXX+XXXXX==')

blob2 = block_blob_service.get_blob_to_text('XXXXX', 'XXXXX.json')
print (blob2.content)

But its not working, its seems old code. error

NameError: name 'BlockBlobService' is not defined

it need <= 2.10 version. I'm using 4.10 and i cant use 2.10 because my program will not work.

Any idea how to solve it?

1 Answer 1

3

Maybe you can try to use this code:

from azure.storage.blob import BlobServiceClient
connection_string=''
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
container_client = blob_service_client.get_container_client("<container name>")
blob_client = container_client.get_blob_client("<blob name>")
blobstr = blob_client.download_blob().readall().decode("utf-8") # read blob content as string

Please refer to Quickstart: Manage blobs with Python v12 SDK

Sign up to request clarification or add additional context in comments.

5 Comments

This working, thank you, but can you tell me if blob is empty I getting b''
It's too late on my side, I will get back to you tomorrow.
I did a test, if the blob is empty, you will get b''
maybe you know how remove it?
Thank you, now its looks nice

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.