不一致的签名不匹配Amazon S3与django管道,s3boto和存储 [英] Inconsistent SignatureDoesNotMatch Amazon S3 with django-pipeline, s3boto and storages
问题描述
编辑:现在也可以在Chrome上发生。
发生在我身上...
几个小时找到,但我最终想到了。
证明如果正确的签名是:
ssCNsAOxLf5vA80ldAI3M0CU2%2Bw =
然后AWS将不接受:
ssCNsAOxLf5vA80ldAI3M0CU2 + w =
其中唯一的区别是将%2B翻译成'+ '。
S3BotoStorage实际上正确地产生它,但编码发生在url方法的最后一行的CachedFilesMixin( return unquote(final_url) code>)。
为了解决这个问题,我派生了一个新的CachedFilesMixin来消除损坏(我应该提到我不知道为什么这个unquote首先存在,所以撤消它可能会导致其他问题)
class MyCachedFilesMixin(CachedFilesMixin):
def url(self,* a,** kw):
s = super
s = s.encode('utf-8','ignore')
方案(*),
如果isinstance(s,unicode) ,netloc,path,qs,anchor = urlparse.urlsplit(s)
path = urllib.quote(path,'/%')
qs = urllib.quote_plus(qs,':& )
return urlparse.urlunsplit((scheme,netloc,path,qs,anchor))
我在哪里使用代码,我发现这里。 p>
希望这有帮助...
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?
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=
Then AWS will NOT accept:
ssCNsAOxLf5vA80ldAI3M0CU2+w=
Where the only difference is the translation of %2B to '+'.
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.
Hope this helps...
这篇关于不一致的签名不匹配Amazon S3与django管道,s3boto和存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!