下面是我用来获取所有存在的存储桶的详细信息的代码,但出现一些错误:
from boto.s3.connection import S3Connection, OrdinaryCallingFormat
from boto.s3.key import Key
host = 'hostname'
port = 9022
accessKeyId = 'accessKeyId'
secretKey = 'secretKey'
conn = S3Connection(aws_access_key_id=accessKeyId,
aws_secret_access_key=secretKey,
host=host,
port=port,
is_secure=False,
calling_format='boto.s3.connection.ProtocolIndependentOrdinaryCallingFormat')
rs = conn.get_all_buckets()
len(rs)
我遇到的错误是:
Traceback (most recent call last):
File "list-bucket.py", line 17, in <module>
rs = conn.get_all_buckets()
File "/usr/lib/python2.7/site-packages/boto/s3/connection.py", line 447 , in get_all_buckets
response.status, response.reason, body)
boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:Error xmlns:n s2="http://www.emc.com/cos/"><Code>1033</Code><Message>Unable to retrieve the secret key for the specified user.</Message></ns2:Error>
答案 0 :(得分:0)
使用boto3
import boto3
s3 = boto3.resource('s3')
for bucket in s3.buckets.all():
print (bucket.name)
答案 1 :(得分:0)
我使用了错误的端口,这就是为什么我会出错,以下是正确的端口:
S3 Protocol API
ports 9020 and 9021 (http and https)