首页 > 解决方案 > 通过 boto 2.49 连接 AWS S3 时遇到问题

问题描述

以下代码适用于生产,但当我尝试在本地设置时失败。

默认主机设置为 s3.amazonaws.com。但是我得到 S3ResponseError: 403 Forbidden 无论我将 is_secure 设置为 True 还是 False 以及是否添加了 calling_format = boto.s3.connection.OrdinaryCallingFormat() 。

我尝试在我的 S3 存储桶上搜索,端点是http://bucket_name.s3-website-us-east-1.amazonaws.com。所以我通过环境变量将主机设置为 s3-website-us-east-1.amazonaws.com。而且我遇到了 SSLError 异常,无论 is_secure 是 True 还是 False,都会重新连接 call_format = boto.s3.connection.OrdinaryCallingFormat()。我也因为没有calling_format但将is_secure设置为True而遇到了同样的错误,而S3ResponseError: 404 Not Found因为没有calling_format并将is_secure设置为False。

原始代码没有 calling_format 和 is_secure 参数。这些是我在其他帖子中发现的。

import boto
import boto.s3.connection
c = boto.connect_s3(aws_access_key_id='********',
                                aws_secret_access_key='*********',
                                host=endpoint)
b = c.get_bucket(bucket_name)

标签: pythonamazon-web-servicesamazon-s3boto

解决方案


推荐阅读