使用azure作为Django的存储后端(使用django-storages)

时间:2015-10-15 14:52:27

标签: python python-3.x azure azure-storage-blobs django-1.8

我正在使用过去使用的django-storage来使用AWS S3。但是对于Microsoft Azure,我遇到了错误,这些错误在google上没有返回任何结果。

我正在使用python 3和Django 1.8.4进行开发。我正在使用django-storages和django-storages-redux来支持python 3。

调用./manage.py collectstatic并输入yes时,我会收到两个(!)错误:

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'

我遵循了使用天蓝色here的django-storage的微薄说明。

任何想法可能导致此错误的原因是什么?有没有人成功地使用azure作为存储和静态文件后端部署django 1.8应用程序?

编辑:我在django-storages模块中乱砍了一下: 使用

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

而不仅仅是

self._connection = azure.storage.BlobService(

但是现在我得到了不同的错误,这让我相信这个问题实际上更深入了。

2 个答案:

答案 0 :(得分:2)

我发现了这个问题:

django-storages-redux简单过时,与最新版本的azure sdk不兼容

作者的拉动请求正在进行中:

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

我在这里做了自己的quickfix:

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

答案 1 :(得分:0)

由于您在我们的存储库顶部使用存储平台,因此我们的支持可能会受到限制。看起来重组和重命名python客户端库的部分和您正在使用的“Azure-Storage”平台没有更新其工具的更改。其他人也有使用这个平台的类似问题。请参阅针对Django-storage提交的以下问题:
https://bitbucket.org/david/django-storages/issues/225/azure-storages-are-incorrectly-imported

查看Django解决方案的“后端”文件,看起来这比直接使用我们的存储服务提供了极少的便利。您可能需要考虑使用我们的库,因为它将为您提供最大的数据存储灵活性。如果您更喜欢使用Django存储,您可以联系他们,看看他们是否会修复它或分叉他们的代码库并自行修复。您可以在此处查看我们为改进此库所做的所有工作: https://github.com/Azure/azure-storage-python/tree/dev

谢谢!