python – 使用boto for AWS S3 Buckets for Signature V4
作者:互联网
我在区域法兰克福使用Python-Boto SDK for S3 Buckets时遇到问题.根据Amazon link,该地区仅支持V4.
document解释了如何为Boto SDK添加V4支持.
我添加了一个新的部分:
if not boto.config.get('s3', 'use-sigv4'):
boto.config.add_section('s3')
boto.config.set('s3', 'use-sigv4', 'True')
然后我创建了新连接并获得了所有桶:
connection = S3Connection(accesskey, secretkey, host=S3Connection.DefaultHost)
buckets = connection.get_all_buckets()
它工作正常,但后来我试图获取我的桶的所有键:
for bucket in buckets:
bucket.get_all_keys()
我得到以下内容:
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>
它为什么会发生?
之后我连接到该地区并获得所有需要的数据:
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()
我该如何正确修理?
解决方法:
我使用Boto时遇到了同样的问题.该地区是法兰克福,错误地区出错.我的解决方案只是将主机(从这个页面http://docs.aws.amazon.com/general/latest/gr/rande.html获得的URI)指向’s3.eu-central-1.amazonaws.com’而不是默认的’s3.amazonaws.com’
s3 = boto.s3.connect_to_region('eu-central-1',
aws_access_key_id=accesskey,
aws_secret_access_key=secretkey,
host='s3.eu-central-1.amazonaws.com')
标签:python,amazon-web-services,amazon-s3,boto 来源: https://codeday.me/bug/20190927/1823685.html