ImportError: cannot import name 'BlobService' when using Azure Backend

前端 未结 5 1694
陌清茗
陌清茗 2020-12-10 07:02

I followed these instructions to set up Azure as my backend service: http://django-storages.readthedocs.io/en/latest/backends/azure.html

Also added additional packag

相关标签:
5条回答
  • 2020-12-10 07:14

    In newer versions of azure-storage-blob the import BlockBlobService has been renamed to BlobServiceClient.

    Updating your import statement to below should resolve your issue:

    from azure.storage.blob import BlobServiceClient
    

    An example of this can seen in the documentation here.

    0 讨论(0)
  • 2020-12-10 07:15

    I had to downgrade to azure-storage-0.20.0 which fixed the issue, the newer versions couldn't find the BlobService class.

    0 讨论(0)
  • 2020-12-10 07:22

    Strange... In Azure official documentation, it says you need to from azure.storage.blob import BlockBlobService, but what you did is from azure.storage.blob.blobservice import BlobService and from azure.storage import BlobService.

    So why don't you just follow the official documentation?

    0 讨论(0)
  • 2020-12-10 07:33

    Before the merge the current azure storage library doesn't work. So to get this to work I had to install a private fork of Django storages:

    I forked: https://github.com/guydou/django-storages/tree/upgrade_azure and pointed to my own repo:

    pip3 install -e 'git+https://github.com/mikebz/django-storages.git#egg=upgrade_azure'
    

    then install blob library and azure SDK:

    pip3 install azure
    pip3 install azure-storages==0.34.3
    

    After that the configuration seemed to work. The final requirements document from azure were this: (venv) Mikes-MacBook:drhazelapp mikebz$ pip3 freeze

    adal==0.4.7
    appnope==0.1.0
    asn1crypto==0.23.0
    astroid==1.5.3
    azure==2.0.0
    azure-batch==3.0.0
    azure-common==1.1.8
    azure-datalake-store==0.0.17
    azure-graphrbac==0.30.0
    azure-keyvault==0.3.7
    azure-mgmt==1.0.0
    azure-mgmt-authorization==0.30.0
    azure-mgmt-batch==4.0.0
    azure-mgmt-cdn==0.30.3
    azure-mgmt-cognitiveservices==1.0.0
    azure-mgmt-compute==1.0.0
    azure-mgmt-containerregistry==0.2.1
    azure-mgmt-datalake-analytics==0.1.6
    azure-mgmt-datalake-nspkg==2.0.0
    azure-mgmt-datalake-store==0.1.6
    azure-mgmt-devtestlabs==2.0.0
    azure-mgmt-dns==1.0.1
    azure-mgmt-documentdb==0.1.3
    azure-mgmt-iothub==0.2.2
    azure-mgmt-keyvault==0.31.0
    azure-mgmt-logic==2.1.0
    azure-mgmt-monitor==0.2.1
    azure-mgmt-network==1.0.0
    azure-mgmt-nspkg==2.0.0
    azure-mgmt-rdbms==0.1.0
    azure-mgmt-redis==4.1.0
    azure-mgmt-resource==1.1.0
    azure-mgmt-scheduler==1.1.3
    azure-mgmt-sql==0.5.3
    azure-mgmt-storage==1.0.0
    azure-mgmt-trafficmanager==0.30.0
    azure-mgmt-web==0.32.0
    azure-nspkg==2.0.0
    azure-servicebus==0.21.1
    azure-servicefabric==5.6.130
    azure-servicemanagement-legacy==0.20.6
    azure-storage==0.34.3
    certifi==2017.7.27.1
    cffi==1.11.2
    chardet==3.0.4
    cryptography==2.1.1
    decorator==4.1.2
    Django==1.11.5
    django-extensions==1.9.1
    -e git+https://github.com/mikebz/django-storages.git@5d073159adc0138f5acef121c2d578f4eba96d7c#egg=django_storages
    django-webpack-loader==0.5.0
    gunicorn==19.7.1
    idna==2.6
    ipython==6.2.1
    ipython-genutils==0.2.0
    isodate==0.6.0
    isort==4.2.15
    jedi==0.11.0
    keyring==10.4.0
    lazy-object-proxy==1.3.1
    mccabe==0.6.1
    msrest==0.4.17
    msrestazure==0.4.15
    oauthlib==2.0.4
    olefile==0.44
    parso==0.1.0
    pep8==1.7.0
    pexpect==4.2.1
    pickleshare==0.7.4
    Pillow==4.3.0
    prompt-toolkit==1.0.15
    ptyprocess==0.5.2
    pycparser==2.18
    Pygments==2.2.0
    PyJWT==1.5.3
    pylint==1.7.2
    python-dateutil==2.6.1
    pytz==2017.2
    requests==2.18.4
    requests-oauthlib==0.8.0
    simplegeneric==0.8.1
    six==1.10.0
    traitlets==4.3.2
    urllib3==1.22
    wcwidth==0.1.7
    whitenoise==3.3.1
    wrapt==1.10.11
    
    0 讨论(0)
  • 2020-12-10 07:39

    When you pip install azure, you installed azure-storage 0.34.3 (tutorial 1). When you followed the second tutorial, you installed azure-storage-blob 0.37.0. This is where you got issues, there is massive breaking changes in 0.37.0 in the namespaces:

    https://github.com/Azure/azure-storage-python/blob/master/BreakingChanges.md#version-0370

    See in the ChangeLog that azure-storage <= 0.36 is incompatible with azure-storage-blob >= 0.37. You silently replaced some code file of 0.34.3 by 0.37.0 version.

    In you second test, you said you did:

    pip3 install azure-storage-blob
    pip3 install azure
    

    Package are still incompatible, but you did it in a reverse order, where you crushed your 0.37.0 version with the 0.34.3 one this time. It's why it works.

    TLDR, someone needs to update django-storages to support azure-storage-blob >= 0.37.0. In the mean time, stick to azure-storage <= 0.36 and DON'T install azure-storage-blob at all.

    0 讨论(0)
提交回复
热议问题