how to read seismic data from blob storage in python (Without download)

Viewed 81

Trying to read data in a blob storage in python without downloading

Code


    from azure.storage.blob import BlobServiceClient

   STORAGEACCOUNTURL = ""
   STORAGEACCOUNTKEY = ""
   CONTAINERNAME = ""
   BLOBNAME = ""

   blob_service_client_instance = BlobServiceClient(
   account_url=STORAGEACCOUNTURL, credential=STORAGEACCOUNTKEY)

   blob_client_instance = blob_service_client_instance.get_blob_client(
    CONTAINERNAME, BLOBNAME, snapshot=None)
blob_data = blob_client_instance.download_blob()
   data = blob_data.readall()
   print(data)

Error

ImportError: cannot import name 'BlobServiceClient' from 'azure.storage.blob' (C:\Users\Anaconda3\lib\site-packages\azure\storage\blob_init_.py)

1 Answers

I tried in my environment that i can read the files in blob storage successfully.

ImportError: cannot import name 'BlobServiceClient' from 'azure.storage.blob' (C:\Users\Anaconda3\lib\site-packages\azure\storage\blob__init__.py)

The error occurs due to module in not installed properly kindly check the below commands

Pip3 uninstall azure-storage.blob

once uninstall again install the proper azure-storage module

 pip3 install azure-storage.blob

Code:

from azure.storage.blob import BlobServiceClient

import os

STORAGEACCOUNTURL = "<Your storage account url>"

STORAGEACCOUNTKEY = "your storage account key"

CONTAINERNAME = "container name"

BLOBNAME = "pandas.json"

blob_service_client_instance = BlobServiceClient(

account_url=STORAGEACCOUNTURL, credential=STORAGEACCOUNTKEY)

blob_client_instance = blob_service_client_instance.get_blob_client(

CONTAINERNAME, BLOBNAME)

blob_data = blob_client_instance.download_blob()

data = blob_data.readall()

print(data)

Portal:

enter image description here

Portal:

enter image description here

Output:

enter image description here

Updated

When you have tried with lower version azure blob storage you will get an error below 12.0.0 will not below

  • BlobServiceClient is introduced in 12.0.0.

When I tried with environment I got an same error:

enter image description here

I run the upgraded version of azure blob storage with commands:

pip install azure-storage-blob==12.13.1

Now when I run the code and got output successfully.

enter image description here

Related