Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 为什么获取botocore.exceptions.ClientError:调用HeadObject操作时出错(403):禁止?_Django_Python 3.x_Amazon S3_Boto3 - Fatal编程技术网

Django 为什么获取botocore.exceptions.ClientError:调用HeadObject操作时出错(403):禁止?

Django 为什么获取botocore.exceptions.ClientError:调用HeadObject操作时出错(403):禁止?,django,python-3.x,amazon-s3,boto3,Django,Python 3.x,Amazon S3,Boto3,我在尝试使用S3 bucket作为AWS ElasticbeanStalk部署的一部分运行runmanage.py collectstatic时得到了这个回溯 File "./src/manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/core/ma

我在尝试使用S3 bucket作为AWS ElasticbeanStalk部署的一部分运行run
manage.py collectstatic
时得到了这个回溯

  File "./src/manage.py", line 10, in <module>
  execute_from_command_line(sys.argv)
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
  utility.execute()
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
  self.execute(*args, **cmd_options)
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/core/management/base.py", line 353, in execute
  output = self.handle(*args, **options)
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 162, in handle
  if self.is_local_storage() and self.storage.location:
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 216, in is_local_storage
  return isinstance(self.storage, FileSystemStorage)
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/utils/functional.py", line 213, in inner
  self._setup()
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 491, in _setup
  self._wrapped = get_storage_class(settings.STATICFILES_STORAGE)()
  File "/opt/python/bundle/3/app/src/core/storage.py", line 64, in __init__
  super(StaticStorage, self).__init__(*args, **kwargs)
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 376, in __init__
  self.hashed_files = self.load_manifest()
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 386, in load_manifest
  content = self.read_manifest()
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 380, in read_manifest
  with self.open(self.manifest_name) as manifest:
  File "/opt/python/run/venv/local/lib64/python3.6/site-packages/django/core/files/storage.py", line 33, in open
  return self._open(name, mode)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/storages/backends/s3boto3.py", line 464, in _open
  f = S3Boto3StorageFile(name, mode, self)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/storages/backends/s3boto3.py", line 72, in __init__
  self.obj.load()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/boto3/resources/factory.py", line 505, in do_action
  response = action(self, *args, **kwargs)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/boto3/resources/action.py", line 83, in __call__
  response = getattr(parent.meta.client, operation_name)(**params)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/botocore/client.py", line 357, in _api_call
  return self._make_api_call(operation_name, kwargs)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/botocore/client.py", line 661, in _make_api_call
  raise error_class(parsed_response, operation_name)
  botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden
   (ElasticBeanstalk::ExternalInvocationError)

在部署代码存储库之前,请确保已将代码提交到代码存储库

试试看,我认为这不是问题所在,因为ElasticBeanstalk和当前EC2实例位于同一区域(而S3没有区域)。此外,该帐户设置为始终在eu-west-2中打开(当使用ElasticBeanstalk实例时)。但是如果这是一个问题,我该如何强制ElasticBeanstalk在eu-west-2中创建EC2实例?我认为ElasticBeanstalk是一种区域服务@Shafik你没有得到许可这是重点。你是如何确保你拥有它的?您是否已分配IAM角色或使用API密钥?对于公共测试,您是否设置了正确的桶策略?如果没有这一点,它将不会公开。@Arunmainthankamalana在这些地区比在美国东部(北弗吉尼亚州)、亚太地区(东京)、欧盟(爱尔兰)、美国西部(俄勒冈州)和美国西部(北加利福尼亚州)可用的多
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "ListObjectsInBucket",
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket"
            ],
            "Principal": "*",
            "Resource": [
                "arn:aws:s3:::my-bucket-name"
            ]
        },
        {
            "Sid": "AllObjectActions",
            "Effect": "Allow",
            "Action": "s3:*Object",
            "Principal": "*",
            "Resource": [
                "arn:aws:s3:::my-bucket-name/*"
            ]
        }, ,
        {
            "Sid": "PublicWrite",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:PutObject"
            ],
            "Resource": [
                "arn:aws:s3:::my-bucket-name/*"
            ]
        }
    ] }