gpt4 book ai didi

python - 如何使用 Boto 向端点发送请求

转载 作者:太空狗 更新时间:2023-10-30 00:50:19 24 4
gpt4 key购买 nike

我正在尝试使用以下代码列出 S3 容器中的项目。

import boto.s3
from boto.s3.connection import OrdinaryCallingFormat

conn = boto.connect_s3(calling_format=OrdinaryCallingFormat())
mybucket = conn.get_bucket('Container001')

for key in mybucket.list():
print key.name.encode('utf-8')

然后我得到以下错误。

Traceback (most recent call last):
File "test.py", line 5, in <module>
mybucket = conn.get_bucket('Container001')
File "/usr/lib/python2.7/dist-packages/boto/s3/connection.py", line 370, in get_bucket
bucket.get_all_keys(headers, maxkeys=0)
File "/usr/lib/python2.7/dist-packages/boto/s3/bucket.py", line 358, in get_all_keys
'', headers, **params)
File "/usr/lib/python2.7/dist-packages/boto/s3/bucket.py", line 325, in _get_all
response.status, response.reason, body)
boto.exception.S3ResponseError: S3ResponseError: 301 Moved Permanently
<?xml version="1.0" encoding="UTF-8"?>
PermanentRedirectThe bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.99EBDB9DE3B6E3AF
Container001
<HostId>5El9MLfgHZmZ1UNw8tjUDAl+XltYelHu6d/JUNQsG3OaM70LFlpRchEJi9oepeMy</HostId><Endpoint>Container001.s3.amazonaws.com</Endpoint></Error>

我试图搜索如何向指定端点发送请求,但没有找到有用的信息。

如何避免此错误?

最佳答案

正如@garnaat 提到的和@Rico answered in another question connect_to_region 使用 OrdinaryCallingFormat:

conn = boto.s3.connect_to_region(
region_name = '<your region>',
aws_access_key_id = '<access key>',
aws_secret_access_key = '<secret key>',
calling_format = boto.s3.connection.OrdinaryCallingFormat()
)
bucket = conn.get_bucket('<bucket name>')

关于python - 如何使用 Boto 向端点发送请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22258738/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com