问题描述
我正在尝试将Django应用程序配置为在AWS S3存储桶中托管图像文件,但是图像不会加载.而是,我收到以下错误消息:'不支持您提供的授权机制.请使用AWS4-HMAC-SHA256'
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
最初,我的配置中未包含AWS_S3_REGION_NAME,因为在S3控制台中显示"S3不需要选择区域".我读到的有关错误消息的内容表明这是必要的,但是将其添加到配置中并没有帮助.我还遵循AWS指南( https ://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAWSSDK.html ),但这也没有帮助.
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.
推荐答案
我不确定为什么在配置文件中设置use-sigv4 = True
对您不起作用.您可以改为设置环境变量:
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')
这篇关于Amazon Web Services-Django中的S3“不支持您提供的授权机制"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!