boto3 site-packages在collectstatic上的S3Response语法错误

时间:2017-08-17 14:44:12

标签: python django amazon-s3 boto3 django-storage

django-storages文档建议使用boto3来管理S3的静态文件存储。希望这个配置能够正常运行但是它的错误

requirements.txt

boto3==1.4.6
botocore==1.6.3
django-storages==1.1.4

prod.py [设置]

from .common import *
from storages.backends.s3boto import S3BotoStorage

...

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_ACCESS_KEY_ID = ENV_STR('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = ENV_STR('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = ENV_STR('AWS_STORAGE_BUCKET_NAME')
S3_URL = 'http://s3.amazonaws.com/%s/static/' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = S3_URL
MEDIA_URL = 'http://s3.amazonaws.com/%s/media/' % 
AWS_STORAGE_BUCKET_NAME
ADMIN_MEDIA_PREFIX = STATIC_URL + '/admin/'
AWS_S3_ENCRYPTION = True
AWS_IS_GZIPPED = True

但在manage.py collectstatic上运行测试--noinput因存储/后端/ s3boto.py中的存储包中的语法错误而失败:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
execute_from_command_line(sys.argv)
  File "/home/ubuntu/virtualenvs/venv-3.5.3/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
  File "/home/ubuntu/virtualenvs/venv-3.5.3/lib/python3.5/site-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
  File "/home/ubuntu/virtualenvs/venv-3.5.3/lib/python3.5/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
  File "/home/ubuntu/virtualenvs/venv-3.5.3/lib/python3.5/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
  File "/home/ubuntu/virtualenvs/venv-3.5.3/lib/python3.5/site-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/opt/circleci/python/3.5.3/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 673, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/ubuntu/brightest-list/project/settings/prod.py", line 7, in <module>
from storages.backends.s3boto import S3BotoStorage
 File "/home/ubuntu/virtualenvs/venv-3.5.3/lib/python3.5/site-packages/storages/backends/s3boto.py", line 139
except S3ResponseError, e:
                      ^
 SyntaxError: invalid syntax

运行python 3.我最初的假设是依赖版本冲突,但我尝试卸载并重新安装boto3和存储无效。感谢任何指导或建议,否则我可能会卸载boto3并恢复到boto。

1 个答案:

答案 0 :(得分:2)

django-storages==1.1.4不支持python3。此版本为2012,因此我不建议使用此类旧版本。 This问题提供了有关它的更多信息。尝试使用1.5或更新版本的新版本。您还可以review代码,您将看到它与python3.x兼容。