简体   繁体   English

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

[英]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_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>')

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.

相关问题 如何使用flask将异步请求发送到具有小超时会话的端点? - How to send asynchronous request using flask to an endpoint with small timeout session? python:boto3 _send_request() 错误 - python: boto3 _send_request() error 如何在应用程序启动时向 EndPoint 发送请求 - How do I Send Request to EndPoint on application Startup 如何查看Boto3 HTTPS请求字符串 - How to view Boto3 HTTPS request string 如何处理boto中的请求超时(408)错误? - How to handle request timeout(408) error in boto? 如何使用 Python-Requests 将 POST 请求发送到 Java Serverlet 端点 - How to send POST request using Python-Requests to a Java Serverlet Endpoint 如何通过 python 请求库将 Starlette FormData 数据结构发送到 FastAPI 端点 - How to send a Starlette FormData data structure to a FastAPI endpoint via python request library 设置boto3 SQS的端点 - Set the endpoint for boto3 SQS 在boto2中使用本地端点 - using local endpoint with boto2 如何添加 http 标头以及数据以使用 Oauth2Session (requests_oauthlib) 将 POST 请求发送到 API 端点? - How to add http headers along with data to send a POST request to an API endpoint using Oauth2Session (requests_oauthlib)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM