本文介绍了将boto用于适用于Signature V4的AWS S3存储桶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将法兰克福地区的S3存储桶使用Python-Boto SDK时遇到问题.根据 Amazon链接,该区域将仅支持V4.此文档说明了如何添加对Boto SDK的V4支持.我添加了一个新部分:

I have a problem with using Python-Boto SDK for S3 Buckets for region Frankfurt. According to Amazon link this region will only support V4. This document explains how to add V4 support for Boto SDK. I have added a new section:

if not boto.config.get('s3', 'use-sigv4'):
    boto.config.add_section('s3')
    boto.config.set('s3', 'use-sigv4', 'True')

然后我创建了新连接并获得了所有存储桶:

and then I have created new connection and got all buckets:

connection = S3Connection(accesskey, secretkey, host=S3Connection.DefaultHost)
buckets = connection.get_all_buckets()

它工作正常,但后来我尝试获取存储桶的所有密钥:

it works fine, but then I tried to get all keys for my bucket:

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>

为什么会发生?之后,我连接到该区域并获取了所有需要的数据:

Why did it occur?After that I connected to the region and got all needed data:

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 )更改为's3.eu-central-1.amazonaws.com',而不是默认设置's3.amazonaws.com'

I had the same issue using Boto. The region was Frankfurt and got errors about wrong regions. The solution for me was just to point a host (an URI got from this page http://docs.aws.amazon.com/general/latest/gr/rande.html) to 's3.eu-central-1.amazonaws.com' instead of default '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')

这篇关于将boto用于适用于Signature V4的AWS S3存储桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 18:57