python - 为什么将错误的区域发送到 Amazon S3 存储桶查询?
问题描述
我正在尝试流式传输存储在 Amazon S3 存储桶中的音乐。
import boto3
SERVICE_NAME = 's3'
REGION_NAME = 'eu-west-2'
def generate_presigned_url(bucket_name, object_key, expiry=3600):
client = boto3.client("s3",region_name=REGION_NAME,
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY)
response = client.generate_presigned_url(
'get_object',
Params={'Bucket': bucket_name,
'Key': object_key},
ExpiresIn=expiry)
return response
url = generate_presigned_url('bucket','music.mp3',3600)
print(url)
输出(重新格式化,以便您可以看到...):
https://bucket.s3.amazonaws.com/music.mp3?
X-Amz-Algorithm=AWS4-HMAC-SHA256&
X-Amz-Credential=[redacted]%2Feu-west-[etc]
这失败并出现以下错误:
Error parsing the X-Amz-Credential parameter;
the region 'eu-west-2' is wrong; expecting 'us-east-1'
任何想法出了什么问题?正确的区域位于生成的 URL 中。
我已经阅读了有关此错误的所有内容,但到目前为止还没有运气。
解决方案
也许您在 ~/.aws/credentials 或 ~/.aws/config 中的 [default] 配置文件中的区域设置为另一个并且它正在创建冲突?
你也可以尝试设置一个配置:
my_config = Config(
region_name = 'us-west-2',
signature_version = 'v4',
retries = {
'max_attempts': 10,
'mode': 'standard'
})
client = boto3.client('s3', config=my_config)
推荐阅读
- php - 获取同一模型中的模型数据字段
- c# - 使用 .NET CORE 发布和获取
- android - 带有背景颜色的按钮,波纹效果仅在左上角呈现
- mpdf - 在版本 7 中,mpdf 不以小写罗马数字显示页码
- java - 火花发射器。java.lang.NoSuchMethodError:org.yaml.snakeyaml.Yaml。
- java - 在java中创建一个在paintComponent之外绘制的函数
- node.js - MongoError:写入批量大小必须在 1 到 100000 之间。得到 0 个操作
- mongodb - 从另一个更新集合需要太长时间
- python - 使用 joblib 的全局对象
- android - 如何以所有设备看起来都相同的边距定位视图?