【问题标题】:How to fix "AuthorizationHeaderMalformed when calling the GetObject operation" error in AWS s3 boto3如何修复 AWS s3 boto3 中的“调用 GetObject 操作时出现 AuthorizationHeaderMalformed”错误
【发布时间】:2020-02-03 10:58:55
【问题描述】:

当我尝试运行非常简单的 Python 脚本从 s3 存储桶中获取对象时:

import boto3

s3 = boto3.resource('s3',
 region_name="eu-east-1",
 verify=False,
 aws_access_key_id="QxxxxxxxxxxxxxxxxxxxxxxxxFY=",
 aws_secret_access_key="c1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxYw==")

obj = s3.Object('3gxxxxxxxxxxs7', 'dk5xxxxxxxxxxn94')
result = obj.get()['Body'].read().decode('utf-8')

print(result)

我遇到了一个错误:

$ python3 script.py

Traceback (most recent call last):
  File "script.py", line 7, in <module>
    result = obj.get()['Body'].read().decode('utf-8')
  File "//anaconda3/lib/python3.7/site-packages/boto3/resources/factory.py", line 520, in do_action
    response = action(self, *args, **kwargs)
  File "//anaconda3/lib/python3.7/site-packages/boto3/resources/action.py", line 83, in __call__
    response = getattr(parent.meta.client, operation_name)(**params)
  File "//anaconda3/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "//anaconda3/lib/python3.7/site-packages/botocore/client.py", line 661, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: 

An error occurred (AuthorizationHeaderMalformed) 
when calling the GetObject operation:
 The authorization header is malformed; the authorization component 
"Credential=QUtJxxxxxxxxxxxxxxxxxlZPUFY=/20191005/us-east-1/s3/aws4_request" 
is malformed.

我不确定是什么原因造成的,值得补充一下:

  • 我不知道什么是存储桶区域(不要问为什么),但我尝试手动连接到所有存储区(通过将命令中的默认区域名称更改为每个区域)但没有成功。
  • 我无权访问存储桶配置。以及 aws 控制台中的任何内容。我只有密钥 ID、秘密、存储桶名称和对象名称。

【问题讨论】:

  • 您的密钥好像不对,请检查。
  • 这个错误的原因通常是凭据有问题,当然我添加了'xxx'是为了不将它们公开。
  • 我从未见过访问密钥有=,但我不确定。

标签: amazon-web-services amazon-s3 boto3


【解决方案1】:

AWS-Access-Key-ID 总是AKIA 开头(对于 IAM 用户)或以 ASIA 开头(对于来自安全令牌服务的临时凭证),如 中的 IAM Identifiers 中所述AWS Identity and Access Management 用户指南

您使用的值似乎不是其中之一,因为它以 QUtJ... 开头...所以这不是您应该在此处使用的值。您使用的似乎不是 AWS-Access-Key-ID。

【讨论】:

    猜你喜欢
    • 2020-12-11
    • 1970-01-01
    • 2017-09-28
    • 2018-03-20
    • 1970-01-01
    • 1970-01-01
    • 2018-06-08
    • 2021-09-23
    • 1970-01-01
    相关资源
    最近更新 更多