如何使用boto获取存储桶详细信息

How to get bucket details using boto

下面是我用来获取其中存在的所有存储桶的详细信息的代码,但出现了一些错误:

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>

使用 boto3

import boto3
s3 = boto3.resource('s3')
for bucket in s3.buckets.all():
    print (bucket.name)

我使用了错误的端口,这就是我收到错误的原因,以下是正确的端口:

S3 Protocol API

ports 9020 and 9021 (http and https)