【问题标题】:How to send request to endpoint with Boto如何使用 Boto 向端点发送请求
【发布时间】:2017-03-30 00:45:17
【问题描述】:

我正在尝试使用以下代码列出 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>

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

如何避免这个错误?

【问题讨论】:

  • 如果您在没有calling_format 的情况下尝试conn = boto.connect_s3(),是否还会出现错误?
  • 这给了我一个不同的错误:boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden
  • 签出this
  • @Drewness 根据该页面,这是一个错误。但是该线程已有 9 个月的历史。
  • 是的,是的。您可以尝试他们建议的分支,因为他们无法复制问题。

标签: python amazon-s3 boto


【解决方案1】:

正如@garnaat 提到的和@Rico answered in another question connect_to_regionOrdinaryCallingFormat 一起使用:

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>')

【讨论】:

    【解决方案2】:

    在终端运行

    纳米~/.boto

    如果有一些配置尝试评论或重命名文件并重新连接。 (对我有帮助)

    http://boto.cloudhackers.com/en/latest/boto_config_tut.html

    有 boto 配置文件目录。一个一个看一下并清理它们,它会在默认配置下工作。配置也可能在 .bash_profile、.bash_source ... 我猜你必须只允许 KEY-SECRET

    也尝试使用

    calling_format = boto.s3.connection.OrdinaryCallingFormat()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-17
      • 1970-01-01
      • 2018-07-18
      • 1970-01-01
      • 1970-01-01
      • 2019-09-29
      • 2019-09-28
      • 2021-06-10
      相关资源
      最近更新 更多