1

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?

Kalakutas
  • 124
  • 2
  • 15

1 Answers1

2

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

Frank Borzage
  • 6,292
  • 1
  • 6
  • 19