我在区域法兰克福使用Python-Boto SDK for S3 Buckets时遇到问题.据亚马逊链接,该地区仅支持V4.本文档介绍了如何为Boto SDK添加V4支持.我添加了一个新的部分:
if not boto.config.get('s3', 'use-sigv4'):
boto.config.add_section('s3')
boto.config.set('s3', 'use-sigv4', 'True')
Run Code Online (Sandbox Code Playgroud)
然后我创建了新连接并获得了所有桶:
connection = S3Connection(accesskey, secretkey, host=S3Connection.DefaultHost)
buckets = connection.get_all_buckets()
Run Code Online (Sandbox Code Playgroud)
它工作正常,但后来我试图获取我的桶的所有键:
for bucket in buckets:
bucket.get_all_keys()
Run Code Online (Sandbox Code Playgroud)
我得到以下内容:
S3ResponseError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AuthorizationHeaderMalformed</Code><Message>The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'eu-central-1'</Message><Region>eu-central-1</Region>
Run Code Online (Sandbox Code Playgroud)
它为什么会发生?之后我连接到该地区并获得所有需要的数据:
region_con = boto.s3.connect_to_region('eu-central-1', aws_access_key_id=accesskey, aws_secret_access_key=secretkey)
bucket = region_con.get_bucket(bucket.name)
bucket.get_all_keys()
Run Code Online (Sandbox Code Playgroud)
我该如何正确修理?