当我尝试运行非常简单的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.
我不确定是什么原因引起的,值得补充一下:
答案 0 :(得分:2)
对于IAM用户,AWS-Access-Key-ID 始终始终以AKIA
开头,对于安全令牌服务中的临时凭证,以ASIA
开头,如{{3}中所述}在 AWS身份和访问管理用户指南中。
您使用的值似乎不是其中之一,因为它以QUtJ
开头...因此这不是您应在此处使用的值。您似乎使用的不是AWS-Access-Key-ID。