Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Azure by (5.8k points)

Azure ML Experiments provide ways to read and write CSV files to Azure blob storage through the Reader and Writer modules. However, I need to write a JSON file to blob storage. Since there is no module to do so, I'm trying to do so from within an Execute Python Script module.

# Import the necessary items

from azure.storage.blob import BlobService

def azureml_main(dataframe1 = None, dataframe2 = None):

    account_name = 'mystorageaccount'

    account_key='mykeyhere=='

    json_string='{jsonstring here}'

    blob_service = BlobService(account_name, account_key)

 blob_service.put_block_blob_from_text("upload","out.json",json_string)

    # Return value must be of a sequence of pandas.DataFrame

    return dataframe1,

However, this results in an error: ImportError: No module named azure.storage.blob

This implies that the azure-storage Python package is not installed on Azure ML.

How can I write to Azure blob storage from inside an Azure ML Experiment?

Here's the full error message:

Error 0085: The following error occurred during script evaluation, please view the output log for more information:

---------- Start of error message from Python interpreter ----------

data:text/plain,Caught exception while executing function: Traceback (most recent call last):

  File "C:\server\invokepy.py", line 162, in batch

    mod = import_module(moduleName)

  File "C:\pyhome\lib\importlib\__init__.py", line 37, in import_module

    __import__(name)

  File "C:\temp\azuremod.py", line 19, in <module>

    from azure.storage.blob import BlobService

ImportError: No module named azure.storage.blob

---------- End of error message from Python interpreter----------

Start time: UTC 02/06/2016 17:59:47

End time: UTC 02/06/2016 18:00:00`

1 Answer

0 votes
by (9.6k points)

Instead of using HTTPS, use HTTP to access Azure storage.

client = BlobService(STORAGE_ACCOUNT, STORAGE_KEY, protocol="http")

Download the Azure file that has required libraries and upload it as Data set in AML Studio. Connect it to Zip module from Execute Python script. Write your code and run the experiment.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...