【问题标题】:Django Storage and Boto3 not retrieving Media from AWS S3Django 存储和 Boto3 未从 AWS S3 检索媒体
【发布时间】:2021-11-06 01:29:18
【问题描述】:

我正在使用开发服务器来测试使用 Django 存储和 Boto3 从 AWS S3 上传和检索静态文件。文件上传成功,但我无法检索文件。

这是我得到的:

当我在另一个标签中查看 URL 时,我得到了这个

**This XML file does not appear to have any style information associated with it. The document tree is shown below.**
<Error>
<Code>IllegalLocationConstraintException</Code>
    <Message>The me-south-1 location constraint is incompatible for the region specific endpoint this request was sent to.</Message>
    <RequestId></RequestId>
    <HostId></HostId>
</Error>

我还使用自己的凭据和 IAM 用户配置了 settings.py

AWS_ACCESS_KEY_ID = <key>
AWS_SECRET_ACCESS_KEY = <secret-key>
AWS_STORAGE_BUCKET_NAME = <bucket-name>
AWS_DEFAULT_ACL = None
AWS_S3_FILE_OVERWRITE = False
AWS_S3_REGION_NAME = 'me-south-1'
AWS_S3_USE_SSL = True
AWS_S3_VERIFY = False
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

【问题讨论】:

  • 你的存储桶区域是什么,因为消息清楚地指向了错误的区域
  • 他们都是我检查过很多次的同一个地区

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


【解决方案1】:

请检查您的 AWS Identity & Access Management Console (IAM) 是否为您的访问密钥分配了适当的 S3 权限。

此外,请确保您已安装 AWS CLI 并在您的计算机中设置您的凭证。

您可以尝试运行以下命令并进行验证。

$ aws s3 ls
2018-12-11 17:08:50 my-bucket
2018-12-14 14:55:44 my-bucket2

参考:https://docs.aws.amazon.com/cli/latest/userguide/cli-services-s3-commands.html

【讨论】:

  • IAM 用户设置为程序化,并为其提供了“AmazonS3FullAccess”策略
  • 从您的命令行检查,您是否能够列出您的存储桶。
  • 希望对您有所帮助:github.com/aws/aws-cli/issues/3567
  • AWS 仍然存在必须手动覆盖的端点问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-18
  • 2021-02-15
  • 2013-01-30
  • 2017-09-29
  • 2020-02-24
  • 1970-01-01
相关资源
最近更新 更多