Using azure as a storage backend for Django (using django-storages)

瘦欲@ 提交于 2020-01-05 01:43:09

问题


I am using django-storages which I have used in the past to work with AWS S3. But with Microsoft Azure I am running into errors which return no results on google.

I am developing using python 3 and Django 1.8.4. I am using django-storages and django-storages-redux for python 3 support.

When calling ./manage.py collectstatic and enter yes I get two (!) errors:

Traceback (most recent call last):
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/storages/backends/azure_storage.py", line 44, in exists
    self.connection.get_blob_properties(
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/storages/backends/azure_storage.py", line 34, in connection
    self._connection = azure.storage.BlobService(
AttributeError: 'module' object has no attribute 'BlobService'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/core/management/base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/core/management/base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle
    collected = self.collect()
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 107, in collect
    handler(path, prefixed_path, storage)
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 305, in copy_file
    if not self.delete_file(path, prefixed_path, source_storage):
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 218, in delete_file
    if self.storage.exists(prefixed_path):
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/storages/backends/azure_storage.py", line 46, in exists
    except azure.WindowsAzureMissingResourceError:
AttributeError: 'module' object has no attribute 'WindowsAzureMissingResourceError'

I followed the meager instructions for using django-storages with azure here.

Any Idea what might be causing this error? Has anyone succesfully deployed a django 1.8 app with azure as a storage and static files backend?

edit: I have hacked around a bit in the django-storages module: Using

import azure.storage.blob
self._connection = azure.storage.blob.blobservice.BlobService(

instead of just

self._connection = azure.storage.BlobService(

But now I am getting different errors which makes me believe that this problem actually runs deeper.


回答1:


I have found the issue:

django-storages-redux is simply outdated and not compatible with the newest version of the azure sdk

a pull request by the author is in the works:

https://github.com/jschneier/django-storages/pull/86

I did my own quickfix here:

https://github.com/schumannd/django-storages




回答2:


Since you are using a storage platform on top of our storage library, our support may be limited. It looks like there was a change to restructure and rename parts of the python client lib and the “Azure-Storage” platform you’re using hasn’t updated their tooling. Others have had similar issues using this platform as well. Please see the following issue filed against Django-storages:
https://bitbucket.org/david/django-storages/issues/225/azure-storages-are-incorrectly-imported

Reviewing the “backend” file for your Django solution it looks like this offers you very little convenience over using our storage service directly. You may want to consider using our library since it will give you the most flexibility with data storage. If you prefer to use Django-storages, you could contact them and see if they will fix it or fork their codebase and make the fix yourself. You can see all the work we are doing to improve this library here: https://github.com/Azure/azure-storage-python/tree/dev

Thanks!



来源:https://stackoverflow.com/questions/33151766/using-azure-as-a-storage-backend-for-django-using-django-storages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!