Amazon Web Services - S3 'The authorization mechanism you have provided is not supported' in Django

不想你离开。 提交于 2020-07-23 10:00:42

问题


I am trying to configure my Django application to host image files within an AWS S3 bucket, but the images won't load. Instead, I receive the following error message: 'The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256'

I'm aware that this issue has been raised by others using different languages, and I've tried some suggested solutions but nothing has worked so far. My config settings are displayed below:

# env.py

os.environ.setdefault("AWS_ACCESS_KEY_ID", "**********")
os.environ.setdefault("AWS_SECRET_ACCESS_KEY", "AWS_ACCESS_KEY_ID", "**********")
os.environ.setdefault("AWS_STORAGE_BUCKET_NAME", "mybucket")
os.environ.setdefault("AWS_S3_REGION_NAME", "eu-west-2")

# settings.py

AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
AWS_S3_REGION_NAME = os.environ.get('AWS_S3_REGION_NAME')

AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

# boto.cfg

[s3] use-sigv4 = True

I initially didn't include AWS_S3_REGION_NAME in my configuration because in the S3 console it says 'S3 does not require region selection'. What I read regarding the error message suggested that this was necessary, but adding it to the config hasn't helped. I also added the 'boto.cfg' file, following AWS guidance (https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAWSSDK.html) but this hasn't helped either.


回答1:


I'm not sure why setting use-sigv4 = True in the config file did not work for you. You can set an environment variable instead:

# env.py

os.environ.setdefault('S3_USE_SIGV4', 'True')


来源:https://stackoverflow.com/questions/57591989/amazon-web-services-s3-the-authorization-mechanism-you-have-provided-is-not-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!