我正在使用模拟在 http://127.0.0.1:4569 上运行的 S3 服务器的容器(无需授权或凭据)
我正在尝试使用 python 和 boto3 简单地连接并打印所有存储桶名称的列表
这是我的 docker-compose:
s3:
image: andrewgaul/s3proxy
environment:
S3PROXY_AUTHORIZATION: none
hostname: s3
ports:
- 4569:80
volumes:
- ./data/s3:/data
这是我的代码:
s3 = boto3.resource('s3', endpoint_url='http://127.0.0.1:4569')
for bucket in s3.buckets.all():
print(bucket.name)enter code here
这是我收到的错误消息:
botocore.exceptions.NoCredentialsError: Unable to locate credentials
我试过这个解决方案 => How do you use an HTTP/HTTPS proxy with boto3?
但还是不行,我不明白我做错了什么
请您参考如下方法:
首先,boto3 始终尝试使用 AWS API key 与 S3 服务器握手。即使您的模拟服务器不需要密码,您仍然需要在 .aws/credentials 或程序中指定它们。例如
[default]
aws_access_key_id = x
aws_secret_access_key = x
硬编码虚拟访问 key 示例
import boto3
session = boto3.session(
aws_access_key_id = 'x',
aws_secret_access_key = 'x')
s3 = session.resource('s3', endpoint_url='http://127.0.0.1:4569')
其次,不知道你们的“s3模拟容器”到底靠谱多少,实现的是什么协议(protocol)。为了让生活更轻松,我总是建议任何想要模拟 S3 负载测试或使用 fake-s3 的人
