django - 将collectstatic 与最新版本的Boto、管道和存储一起使用时,x-amz-acl 设置不正确

标签 django boto django-pipeline collectstatic

我正在更新我的应用程序的依赖项。我对requirements.txt进行了以下更改:

  • boto:升级到2.34.0
  • django-pipeline:升级到1.4.2
  • django-require:升级到1.0.6
  • django-storages:最新版本 (1.1.8)

现在,当我尝试在 S3 存储桶中运行collectstatic 时,出现以下错误:

boto.exception.S3ResponseError: S3ResponseError: 400 Bad Request

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InvalidArgument</Code><Message></Message><ArgumentName>x-amz-acl</ArgumentName>
<ArgumentValue>/tmp/tmpDyVin1</ArgumentValue><RequestId>xxx</RequestId>
<HostId>yyy</HostId></Error>

并不感到惊讶,因为显然/tmp/tmpDyVin1not a valid value for x-amz-acl

问题源于指定我自己的类来处理结合了 Boto、Require 和 Pipeline 的静态文件:

settings.py

STATICFILES_STORAGE = 'myapp.storage.OptimizedS3BotoStorage'

存储.py

from pipeline.storage import PipelineMixin
from require.storage import OptimizedFilesMixin
from storages.backends.s3boto import S3BotoStorage

class ReleaseVersionCachedFilesMixin(CachedFilesMixin):

    def hashed_name(self, name, content=None):
        ...

class OptimizedS3BotoStorage(PipelineMixin, OptimizedFilesMixin, ReleaseVersionCachedFilesMixin, S3BotoStorage):
    pass

这与所有这些模块的旧版本完美且一致。深入研究新代码,我发现问题出在这三者的交互上:

  • 何时 S3BotoStorage.__init__()被调用,第一个参数,acl ,作为此 tmp 目录的值传入。这将覆盖之前的值 public-read并导致上述问题。
  • 这个__init__()例程由 CachedFilesMixin.__init__() 调用,它接收 args = ('/tmp/tmpnNUVD9',) .
  • 那个__init__()PipelineMixin.__init__() 调用,它执行以下操作:

def __init__(self, location=None, *args, **kwargs): if not settings.PIPELINE_ENABLED and location is None: location = tempfile.mkdtemp() super(PipelineMixin, self).__init__(location, *args, **kwargs)

所以,问题是Pipeline传入location作为第一个参数,它向下传播并成为 acl .

最佳答案

解决这个令人讨厌的问题的方法似乎只是将 PipelineMixin 移动到我的自定义存储类中参数列表的末尾,但这会破坏 r.js 优化器。解决方案是将此 PIPELINE_ENABLED 标志设置为 True

(文档显示 this flag defaults to not settings.DEBUG ,但这对于您的环境可能不是有意义的依赖项。直到 1.4 之前,PipelineMixin 中才以这种方式使用该标志,但 it's not documented in the directives for upgrading to 1.4 。)

关于django - 将collectstatic 与最新版本的Boto、管道和存储一起使用时,x-amz-acl 设置不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27771184/

相关文章:

django - 将参数传递给 Django 模板中的模型方法

python - 使用Python API读/写Mysql DB

python - 使用 boto 在 S3 上的子桶中插入项目

python - 交叉导入 django/python 时导入错误

html - css下拉菜单排版

django - Django 中的 YAML 文本编辑器字段

python - 如何处理 boto 中的请求超时(408)错误?

django - ValueError : Missing staticfiles manifest entry on Heroku with Docker, django-pipeline, whitenoise

python - Django 1.8.2 不提供所有静态文件 - django-pipeline

python - 运行collectstatic时Django-pipeline找不到文件或目录