简体   繁体   English

Django 收集 static S3 调用 HeadObject 操作时发生错误(403):禁止访问

[英]Django collect static S3 An error occurred (403) when calling the HeadObject operation: Forbidden

I have created a S3 bucket for my Django static files.我为我的 Django static 文件创建了一个 S3 存储桶。 I am able to display the static files from S3 however when I run the python manage.py collectstatic command I get the error "An error occurred (403) when calling the HeadObject operation: Forbidden"我能够显示来自 S3 的 static 文件,但是当我运行python manage.py collectstatic命令时,我收到错误消息“调用 HeadObject 操作时发生错误 (403):禁止访问”

error traceback错误回溯

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/Users/john/Environments/PRM/lib/python3.6/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/Users/john/Environments/PRM/lib/python3.6/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/john/Environments/PRM/lib/python3.6/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/john/Environments/PRM/lib/python3.6/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/Users/john/Environments/PRM/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
    collected = self.collect()
  File "/Users/john/Environments/PRM/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
    handler(path, prefixed_path, storage)
  File "/Users/john/Environments/PRM/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 338, in copy_file
    if not self.delete_file(path, prefixed_path, source_storage):
  File "/Users/john/Environments/PRM/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 248, in delete_file
    if self.storage.exists(prefixed_path):
  File "/Users/john/Environments/PRM/lib/python3.6/site-packages/storages/backends/s3boto3.py", line 469, in exists
    self.connection.meta.client.head_object(Bucket=self.bucket_name, Key=name)
  File "/Users/john/Environments/PRM/lib/python3.6/site-packages/botocore/client.py", line 391, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/john/Environments/PRM/lib/python3.6/site-packages/botocore/client.py", line 719, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden

base_settings.py基本设置.py

# aws settings
AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_STORAGE_BUCKET_NAME')
AWS_DEFAULT_ACL = 'public-read'
AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
# s3 static settings
STATIC_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

Your settings.py looks fine to me.你的 settings.py 对我来说很好。 The problem is with your AWS IAM policy.问题出在您的 AWS IAM 策略上。 403:Forbidden meaning that you do not have proper rights to access the S3 resources/collect static files to your root. 403:Forbidden 意味着您没有适当的权限访问 S3 资源/将 static 文件收集到您的根目录。 You need to check AWS IAM user policy.您需要检查 AWS IAM 用户策略。 Unless I see your IAM user policy, can't say much.除非我看到您的 IAM 用户策略,否则不能说太多。 in the mean time do check this link: Looks similar to the problem you are facing同时请检查此链接: 看起来与您面临的问题相似

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从 S3 下载文件,因为“调用 HeadObject 操作时发生客户端错误 (403):禁止访问” - Unable to download file from S3 because "A client error (403) occurred when calling the HeadObject operation: Forbidden" AWS CLI S3 调用 HeadObject 操作时发生客户端错误 (403):禁止访问 - AWS CLI S3 A client error (403) occurred when calling the HeadObject operation: Forbidden ClientError:调用HeadObject操作时发生错误(403):尝试上传视频时被禁止 - ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden when trying to upload video 尝试在 AWS Lambda Lambda function 中下载文件时如何修复“ClientError:调用 HeadObject 操作时发生错误(403):禁止” - how to fix "ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden" when trying to download file in AWS Lambda function botocore.exceptions.ClientError:调用 HeadObject 操作时发生错误 (403):在 AWS SageMaker 中使用本地模式时禁止 - botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden while using local mode in AWS SageMaker 调用HeadObject操作时出现错误(404):Key“”不存在 - An error occurred (404) when calling the HeadObject operation: Key "" does not exist Collectstatic 失败 - botocore.exceptions.ClientError:调用 HeadObject 操作时发生错误 (404):未找到 - Collectstatic failing - botocore.exceptions.ClientError: An error occurred (404) when calling the HeadObject operation: Not Found AWS S3 Boto3 Python - 调用 DeleteObject 操作时发生错误 (AccessDenied):拒绝访问 - AWS S3 Boto3 Python - An error occurred (AccessDenied) when calling the DeleteObject operation: Access Denied S3:HeadObject 从 Go lambda 调用时返回 403 响应 - S3:HeadObject returns 403 response when invoked from Go lambda `调用 ListBuckets 操作时发生错误(InvalidToken):提供的令牌格式不正确或无效。`w/`aws s3 ls` - `An error occurred (InvalidToken) when calling the ListBuckets operation: The provided token is malformed or otherwise invalid.` w/`aws s3 ls`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM