我是python的新手,我正在尝试检查是否存在或需要创建一个存储桶,但我得到的是这个error
s3 = boto3.resource('s3')
def check_bucket(bucket):
try:
s3.meta.client.head_bucket(Bucket=bucket_name) #Error line <<<<<<<<<<<<<<<<<
print("Bucket Exists!")
return True
except botocore.exceptions.ClientError as e:
# If a client error is thrown, then check that it was a 404 error.
# If it was a 404 error, then the bucket does not exist.
error_code = int(e.response['Error']['Code'])
if error_code == 403:
print("Private Bucket. Forbidden Access!")
return True
elif error_code == 404:
print("Bucket Does Not Exist!")
return False
if_bucket_accessable = check_bucket(bucket_name)发布于 2020-11-15 15:20:51
错误说明找不到凭据。因此您需要在创建s3对象时指定凭据,如下所示:
s3 = boto3.resource('s3',aws_access_key_id=ACCESS_KEY,aws_secret_access_key= SECRET_KEY)在代码中添加访问和密钥是不安全的。因此,您只需使用was cli命令配置一次即可:
aws configure填写执行上述命令时提示的详细信息
发布于 2020-11-15 15:48:27
如果您使用的是windows,此链接可能会很有帮助。
https://www.youtube.com/watch?v=n3KacV0UlSM这个视频将会让你一步一步的走完。如果你卡在什么地方了,请告诉我
https://stackoverflow.com/questions/64842038
复制相似问题