问题描述
我正在使用Amazon S3的django-storage。我稍微间歇地看到以下错误: name = self._normalize_name(self._clean_name(name))\\\
\ n文件\/app/.heroku/venv/lib/python2.7/site-packages/storages/backends/s3boto.py\,第237行,在_normalize_name\\\
名称中)\\\
\\\
SuspiciousOperation :尝试访问https:/plantvillage.s3.amazonaws.com/avatar/hans9_avatar.jpg
请注意 https:
之后的单个 /
。
有谁知道为什么会这样出现?它不会一直发生。在其他情况下,我可以成功地做到这一点。
_normalize_name 在Django上使用URL做了很多花哨,大部分是不必要的。在我的情况下,我只是覆盖 S3BotoStorage :
S3CustomStorage(S3BotoStorage):
def _normalize_name(self,name):
摆脱这个垃圾:http://stackoverflow.com/questions/12535123/django-storages-and-amazon-s3-suspiciousoperation
返回名称
然后在存储属性中使用它:
ImageField(storage = S3CustomStorage())
它适用于具有此基本配置的django simple ImageField:
AWS_ACCESS_KEY_ID = TTTT'
AWS_SECRET_ACCESS_KEY ='XXXX'
AWS_STORAGE_BUCKET_NAME ='ZZZZ'
I'm using django-storages with Amazon S3. I see the following error somewhat intermittently:
name = self._normalize_name(self._clean_name(name))\n\n File \"/app/.heroku/venv/lib/python2.7/site-packages/storages/backends/s3boto.py\", line 237, in _normalize_name\n name)\n\nSuspiciousOperation: Attempted access to 'https:/plantvillage.s3.amazonaws.com/avatar/hans9_avatar.jpg'
Note the single /
after https:
.
Does anyone know why this shows up? It doesn't happen all the time. I can successfully do this in other cases.
_normalize_name does a lot of fancy and mostly unnecessary on Django stuff with the URL. In my case I just override the S3BotoStorage like this:
class S3CustomStorage(S3BotoStorage):
def _normalize_name(self, name):
"""
Get rid of this crap: http://stackoverflow.com/questions/12535123/django-storages-and-amazon-s3-suspiciousoperation
"""
return name
Then use it in the storage property:
ImageField(storage=S3CustomStorage())
And it worked for django simple ImageField with this base configuration:
AWS_ACCESS_KEY_ID = 'TTTT'
AWS_SECRET_ACCESS_KEY = 'XXXX'
AWS_STORAGE_BUCKET_NAME = 'ZZZZ'
这篇关于django-storages和亚马逊s3 - 可疑操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!