For loop Boto3 get_bucket_位置返回:使用变量时拒绝访问

For loop Boto3 get_bucket_位置返回:使用变量时拒绝访问,for-loop,variables,amazon-s3,boto3,For Loop,Variables,Amazon S3,Boto3,我有一个包含S3存储桶列表的文件。我想对它们进行迭代,以获得bucket所在的区域 但是,我遇到了以下错误: botocore.exceptions.ClientError:调用GetBucketLocation操作时发生错误(AccessDenied):拒绝访问 这是我的代码: import boto3 client = boto3.client('s3') with open('test','r') as input_file: for var in input_file:

我有一个包含S3存储桶列表的文件。我想对它们进行迭代,以获得bucket所在的区域

但是,我遇到了以下错误:

botocore.exceptions.ClientError:调用GetBucketLocation操作时发生错误(AccessDenied):拒绝访问

这是我的代码:

import boto3
client = boto3.client('s3')

with open('test','r') as input_file:

    for var in input_file:

        x = var.rstrip('\n')

        response = client.get_bucket_location(Bucket=x)

        print(x)
如果我在(bucket='bucket_name')中硬编码一个bucket名称,那么它只会工作,所以它与权限无关(我确认我之前已经提供了所有必需的权限)


为什么我不能在这个简单的代码中使用变量?以及为什么拒绝访问?

根据boto3文档,当出现权限问题时,将返回“拒绝访问”。然而,现实生活告诉我,当引用的bucket名称不存在时,这个问题也可能出现

在我的例子中,我的列表中第一个bucket的名字有一个拼写错误,因此,对于boto来说,这个bucket不存在,抛出错误消息

仅供参考