【发布时间】:2016-01-22 16:26:25
【问题描述】:
当我简单地运行以下代码时,我总是得到这个错误。
s3 = boto3.resource('s3')
bucket_name = "python-sdk-sample-%s" % uuid.uuid4()
print("Creating new bucket with name:", bucket_name)
s3.create_bucket(Bucket=bucket_name)
我已将我的凭据文件保存在
C:\Users\myname\.aws\credentials,博托应该从那里读取我的凭据。
我的设置错了吗?
这是boto3.set_stream_logger('botocore', level='DEBUG')的输出。
2015-10-24 14:22:28,761 botocore.credentials [DEBUG] Skipping environment variable credential check because profile name was explicitly set.
2015-10-24 14:22:28,761 botocore.credentials [DEBUG] Looking for credentials via: env
2015-10-24 14:22:28,773 botocore.credentials [DEBUG] Looking for credentials via: shared-credentials-file
2015-10-24 14:22:28,774 botocore.credentials [DEBUG] Looking for credentials via: config-file
2015-10-24 14:22:28,774 botocore.credentials [DEBUG] Looking for credentials via: ec2-credentials-file
2015-10-24 14:22:28,774 botocore.credentials [DEBUG] Looking for credentials via: boto-config
2015-10-24 14:22:28,774 botocore.credentials [DEBUG] Looking for credentials via: iam-role
【问题讨论】:
-
您可以通过在代码前添加
boto3.set_stream_logger('botocore', level='DEBUG')来发布调试输出吗?它会显示它在哪里寻找凭据。 -
Boto 似乎为凭据配置文件寻找的位置很少,但显然由于某种原因没有查看我的主目录...
-
尝试将环境变量
HOME设置为指向C:\Users\myname或设置AWS_SHARED_CREDENTIALS_FILE直接指向您的凭据文件。 -
我按照您的描述设置了环境变量 HOME,但现在出现以下错误。
botocore.exceptions.NoRegionError: You must specify a region.*my config file↓ 与我的凭据位于同一文件夹中。[default] ap-northeast-1 -
我可以使用 garnaat's comment 解决问题。