David Lee
David Lee

Reputation: 123

How do I fix the 'BlobService' is not defined' error

I've installed the azure SDK for Python (pip install azure). I've copied the Python code on the MS Azure Machine Learning Batch patch for the ML web-service into an Anaconda Notebook. I've replaced all the place holders in the script with actual values as noted in the scripts comments. When I run the script I get the error: "NameError: global name 'BlobService' is not defined" at the script line "blob_service = BlobService(account_name=storage_account_name, account_key=storage_account_key)". Since the "from azure.storage import *" line at the beginning of the script does not generate an error I'm unclear as to what the problem is and don't know how to fix it. Can anyone point me to what I should correct?

Upvotes: 0

Views: 5605

Answers (4)

guymeetsdata
guymeetsdata

Reputation: 48

BlobService is function you are trying to call, but it is not defined anywhere. It should be defined when you call from azure.storage import *. It is probably not being called, due to a difference in package versions.

Calling from azure.storage.blob import * should work, as it is now invoked correctly.

Upvotes: 0

Rui Martins
Rui Martins

Reputation: 3848

To work fine,

In CentOS and Windows I write:

from azure.storage.blob import BlobService

But in MacOS X I write:

from azure.storage import BlobService

Then I write this:

from sys import platform as _platform
if _platform == "linux" or _platform == "linux2":   # linux
    from azure.storage.blob import BlobService
elif _platform == "darwin": # OS X
    from azure.storage import BlobService
elif _platform == "win32":  # Windows...
    from azure.storage.blob import BlobService

UPDATE 18/02/2016:

Today I did an update today with the command

pip freeze --local | grep -v '^-e' | cut -d = -f 1 | xargs -n1 pip install -U

, and then, azure crashed. THEN, I read in 'https://pypi.python.org/pypi/azure/1.0.3' this:

Upgrading from azure<1.0 is not supported. You must uninstall the old version first.

pip uninstall azure -y
pip uninstall azure-mgmt -y
pip uninstall azure-mgmt-compute -y
pip uninstall azure-mgmt-network -y
pip uninstall azure-mgmt-resource -y
pip uninstall azure-mgmt-storage -y
pip uninstall azure-mgmt-common -y
pip uninstall azure-mgmt-nspkg -y
pip uninstall azure-servicebus -y
pip uninstall azure-storage -y
pip uninstall azure-common -y
pip uninstall azure-nspkg -y
pip install azure

And now works fine

Upvotes: 2

David Lee
David Lee

Reputation: 123

James, I figured it out. I just changed from azure.storage import * to azure.storage.blob import * and it seems to be working.

Upvotes: 1

James Gaunt
James Gaunt

Reputation: 14783

It's been a long time since I did any Python, but BlobStorage is in the azure.storage.blob namespace I believe.

So I don't think your from azure.storage import * is pulling it in.

If you've got a code sample in a book which shows otherwise it may just be out of date.

Upvotes: 0

Related Questions