Is put_block_blob_from_path depreciated?

Question:

I’m currently trying to upload some files to my Azure storage, but can’t seem to achieve that.

from azure.storage.blob import BlockBlobService
data1File=os.path.join(filePath,'data1.csv')
data2File=os.path.join(filePath,'data2.csv')
blockBlobService = BlockBlobService(account_name='NAME', account_key='KEY')
blockBlobService.put_block_blob_from_path('HdiNotebooks/Recommendation_Systems/data/full', 'data1.csv', data1File)
blockBlobService.put_block_blob_from_path('HdiNotebooks/Recommendation_Systems/data/full', 'data2.csv', data2File)

However, I get this error thrown to me:

AttributeError: ‘BlockBlobService’ object has no attribute ‘put_block_blob_from_path’

The code example I had seen previously looked like this:

from azure.storage.blob import BlobService
data1File=os.path.join(filePath,'data1.csv')
data2File=os.path.join(filePath,'data2.csv')
blockBlobService = BlobService(account_name='NAME', account_key='KEY')
blockBlobService.put_block_blob_from_path('HdiNotebooks/Recommendation_Systems/data/full', 'data1.csv', data1File)
blockBlobService.put_block_blob_from_path('HdiNotebooks/Recommendation_Systems/data/full', 'data2.csv', data2File)

However, already in the first line I got the error that there is no such module as “BlobService”. I have gone through the azure package github, but couldn’t figure out where is my mistake.

I’m currently trying to run this code on a Windows machine and Python 3.6.1

Asked By: Yordan Ivanov

||

Answers:

I reviewed the versions of Azure Storage SDK for Python, the version of the APIs you used is less than 0.20.3, and the APIs have changed from version 0.30.0.

You can check your current version via pip freeze | grep azure-storage.

If you want to the old version, you need to first remove the current one via pip uninstall azure-storage and reinstall via pip install azure-storage==0.20.3.

If not, please try to upgrade to the newest one via pip install --upgrade azure-storage and refer to the newest offical tutorial & the latest API reference to use new APIs.

Answered By: Peter Pan
container_name = "flask"
    storage_acc_name = ""
    storage_acc_key = "5MsH80Uea3K/0VIH7LMAsqvHnXIWbrADi9KOhqyYA/3VxL1/VuWVbi1sl15magDT0fz6UR5xj2DH+AStwGrs2Q=="
    service = BlobServiceClient(account_name=storage_acc_name, account_key=storage_acc_key)
    # Dump data into azure blob
    service.put_block_blob_from_path(container_name, "data.json", json.dumps(data))
Answered By: unknown