1

我是新手,我想获取 s3 存储桶的位置,但我仍然有此错误“NoAuthHandlerFound:没有处理程序准备好进行身份验证。检查了 1 个处理程序。['HmacAuthV1Handler'] 检查您的凭据”即使我正在使用访问密钥和密钥?代码是这样的。。

 from boto3.session import Session
   import boto
         
   ACCESS_KEY_ID = '*****'
   SECRET_KEY = '*****'
    
    session = Session(aws_access_key_id = ACCESS_KEY_ID, aws_secret_access_key = SECRET_KEY)
 
    s3 = session.resource('s3')
    bucket = 's3://****'
    my_bucket = s3.Bucket(bucket)
    
    **conn = boto.connect_s3()
    bucket = conn.get_bucket('*****')
    bucket_location = my_bucket.get_location()
    if bucket_location:
        conn = boto.s3.connect_to_region(bucket_location)
        bucket = conn.get_bucket('*****')**
4

1 回答 1

0

您可以只使用get_bucket_location

import boto3

session = boto3.session.Session(aws_access_key_id = ACCESS_KEY_ID, aws_secret_access_key = SECRET_KEY)

s3 = session.client('s3')

response = s3.get_bucket_location(
    Bucket='bucket-name' 
)

print(response['LocationConstraint'])
于 2021-04-27T09:21:19.670 回答