我正在尝试使用 AWS Python SDK BOTO3 生成允许我访问文件的预先设计的 URL。我不断收到此错误
<Error>
<Code>InvalidRequest</Code>
<Message>The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.</Message>
<RequestId>TCS5AKTVFTRPH8E8</RequestId>
<HostId>Kji20SQmp7DM3hdanuW+8xXqDyDQ2U0i15yPwSjjVEOyOrpZBa1/AthiSNaGPUL0feqhunb3ZTo=</HostId>
</Error>
预签名 URL 生成代码直接来自 boto3 文档:https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-presigned-urls.html
我尝试过的事情
- If I generate the URL from the AWS console on the browser, I can access all files
- I have tried generating from the shell, Postman, and Python script
这里的答案都不起作用 - 不支持您提供的授权机制。请使用AWS4-HMAC-SHA256 - Amazon S3:不支持您提供的授权机制。请使用AWS4-HMAC-SHA256
尝试了两周多后,问题真的很简单
我在
~/.aws
的凭证已将区域设置为 us-east-1
,这对于我使用的几乎所有其他 AWS 服务都是如此,除了 s3 之外。我进入凭证文件并将区域更改为我的 s3 存储桶所在的区域并且预签名 URL 有效。
我认为生成错误的原因是 east1 和 east2 是在不同的日期建立的,并使用不同的安全算法(v2 与 v4),因此,出现了有关此的错误。