[英]How to send request to endpoint with Boto
I am trying to list items in a S3 container with the following code. 我试图使用以下代码列出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')
Then I get the following error. 然后我收到以下错误。
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>
I tried to search for how to send requests to the specified end point, but couldn't find useful information. 我试图搜索如何将请求发送到指定的端点,但找不到有用的信息。
How do I avoid this error? 如何避免此错误?
As @garnaat mentioned and @Rico answered in another question connect_to_region
works with OrdinaryCallingFormat
: 正如@garnaat所提及的,@ Rico 在另一个问题中回答, 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>')
in terminal run 在终端运行中
nano ~/.boto 纳米〜/ .boto
if there is some configs try to comment or rename file and connect again. 如果有一些配置尝试注释或重命名文件并再次连接。 (it helps me) (它帮助到我)
http://boto.cloudhackers.com/en/latest/boto_config_tut.html http://boto.cloudhackers.com/en/latest/boto_config_tut.html
there is boto config file directories. 有boto配置文件目录。 take a look one by one and clean them all, it will work by default configs. 看一个一个地清理它们,它将默认配置。 also configs may be in .bash_profile, .bash_source... I guess you must allow only KEY-SECRET 也可以在.bash_profile,.bash_source中配置...我想你必须只允许KEY-SECRET
also try to use 也尝试使用
calling_format = boto.s3.connection.OrdinaryCallingFormat() calling_format = boto.s3.connection.OrdinaryCallingFormat()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.