不一致的签名不匹配

不一致的签名不匹配

本文介绍了不一致的签名不匹配 Amazon S3 与 django-pipeline、s3boto 和存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个由 django-pipeline 和 s3boto 编译的文件:master.css 和 master.js.它们在我的存储桶中设置为公共".但是,当我访问它们时,有时会提供 master.css,有时会出现 SignatureDoesNotMatch 错误.与 master.js 相同.这不会发生在 Chrome 上.我可能会遗漏什么?

I have 2 files compiled by django-pipeline along with s3boto: master.css and master.js. They are set to "Public" in my buckets. However, when I access them, sometimes master.css is served, sometimes it errs with SignatureDoesNotMatch. The same with master.js. This doesn't happen on Chrome. What could I be missing?

编辑:它现在也发生在 Chrome 上.

EDIT: It now happens on Chrome too.

推荐答案

我也遇到过...花了几个小时才找到,但我最终弄明白了.事实证明,如果正确的签名是:

Happened to me too...Took a few hours to find, but I figured it out eventually.Turns out that if the right signature is :

ssCNsAOxLf5vA80ldAI3M0CU2%2Bw=

ssCNsAOxLf5vA80ldAI3M0CU2%2Bw=

那么 AWS 将不接受:

Then AWS will NOT accept:

ssCNsAOxLf5vA80ldAI3M0CU2+w=

ssCNsAOxLf5vA80ldAI3M0CU2+w=

唯一的区别是将 %2B 转换为+".

Where the only difference is the translation of %2B to '+'.

S3BotoStorage 实际上正确地生成它,但编码发生在 CachedFilesMixin 上 url 方法的最后一行 (return unquote(final_url)).为了修复它,我派生了一个新的 CachedFilesMixin 来撤消损坏"(我应该提一下,我不知道为什么这个取消引用首先存在,因此撤消它可能会导致其他问题)

S3BotoStorage actually yields it correctly but the encoding happens on CachedFilesMixin in the final line of the url method (return unquote(final_url)).To fix it, I derived a new CachedFilesMixin to undo the "damage" (I should mention that I don't know why this unquote exists in the first place, so undoing it might cause other problems)

class MyCachedFilesMixin(CachedFilesMixin):
def url(self, *a, **kw):
    s = super(MyCachedFilesMixin, self).url(*a, **kw)
    if isinstance(s, unicode):
        s = s.encode('utf-8', 'ignore')
    scheme, netloc, path, qs, anchor = urlparse.urlsplit(s)
    path = urllib.quote(path, '/%')
    qs = urllib.quote_plus(qs, ':&=')
    return urlparse.urlunsplit((scheme, netloc, path, qs, anchor))

我在哪里使用了我在此处找到的代码.

Where I used the code I found here.

希望这有帮助...

这篇关于不一致的签名不匹配 Amazon S3 与 django-pipeline、s3boto 和存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 03:34