问题:
在settings.py中启用DEFAULT_FILE_STORAGE
会创建TypeError:
Unicode-objects must be encoded before hashing
(以下日志)
DEFAULT_FILE_STORAGE = ''
创建TypeError DEFAULT_FILE_STORAGE = 'app.aws.utils.MediaRootS3Boto3Storage'
创建TypeError 我在做什么?
什么工作?
#DEFAULT_FILE_STORAGE = 'app.aws.utils.MediaRootS3Boto3Storage'
python manage.py collectstatic
并且我的所有静态文件都成功上传到aws上的/ static /文件夹什么打破?
DEFAULT_FILE_STORAGE
设置为任何值会创建此错误消息。日志:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x1103e3ea0>
Traceback (most recent call last):
File "/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/env/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 327, in execute
autoreload.check_errors(django.setup)()
File "/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/env/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/env/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/env/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/env/lib/python3.6/site-packages/photologue/models.py", line 76, in <module>
"Signature: 8a477f597d28d172789f06886806bc55"))
File "/env/lib/python3.6/site-packages/django/core/files/storage.py", line 49, in save
return self._save(name, content)
File "/env/lib/python3.6/site-packages/storages/backends/s3boto3.py", line 452, in _save
self._save_content(obj, content, parameters=parameters)
File "/env/lib/python3.6/site-packages/storages/backends/s3boto3.py", line 467, in _save_content
obj.upload_fileobj(content, ExtraArgs=put_parameters)
File "/env/lib/python3.6/site-packages/boto3/s3/inject.py", line 513, in object_upload_fileobj
ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
File "/env/lib/python3.6/site-packages/boto3/s3/inject.py", line 431, in upload_fileobj
return future.result()
File "/env/lib/python3.6/site-packages/s3transfer/futures.py", line 73, in result
return self._coordinator.result()
File "/env/lib/python3.6/site-packages/s3transfer/futures.py", line 233, in result
raise self._exception
File "/env/lib/python3.6/site-packages/s3transfer/tasks.py", line 126, in __call__
return self._execute_main(kwargs)
File "/env/lib/python3.6/site-packages/s3transfer/tasks.py", line 150, in _execute_main
return_value = self._main(**kwargs)
File "/env/lib/python3.6/site-packages/s3transfer/upload.py", line 692, in _main
client.put_object(Bucket=bucket, Key=key, Body=body, **extra_args)
File "/env/lib/python3.6/site-packages/botocore/client.py", line 314, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/env/lib/python3.6/site-packages/botocore/client.py", line 593, in _make_api_call
request_signer=self._request_signer, context=request_context)
File "/env/lib/python3.6/site-packages/botocore/hooks.py", line 242, in emit_until_response
responses = self._emit(event_name, kwargs, stop_on_response=True)
File "/env/lib/python3.6/site-packages/botocore/hooks.py", line 210, in _emit
response = handler(**kwargs)
File "/env/lib/python3.6/site-packages/botocore/handlers.py", line 210, in conditionally_calculate_md5
calculate_md5(params, **kwargs)
File "/env/lib/python3.6/site-packages/botocore/handlers.py", line 188, in calculate_md5
binary_md5 = _calculate_md5_from_file(body)
File "/env/lib/python3.6/site-packages/botocore/handlers.py", line 202, in _calculate_md5_from_file
md5.update(chunk)
TypeError: Unicode-objects must be encoded before hashing
问题:
DEFAULT_FILE_LOCATION
会触发此错误。包装:
boto3==1.6.4
botocore==1.9.4
Django==2.0.3
django-photologue==3.8.1
django-sortedm2m==1.5.0
django-storages==1.6.5
docutils==0.14
ExifRead==2.1.2
jmespath==0.9.3
Pillow==5.0.0
psycopg2==2.7.4
python-dateutil==2.6.1
python-decouple==3.1
pytz==2018.3
s3transfer==0.1.13
six==1.11.0
版本号
我已利用的资源
提前感谢您的帮助!
答案 0 :(得分:2)
好的,所以我看到第二篇文章建议将该设置用于DEFAULT_FILE_STORAGE,但对我来说这看起来有点不寻常。
引用http://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html,您将使用:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
您的媒体根。