How to capture botocore's NoSuchKey exception?

后端 未结 4 1388
时光说笑
时光说笑 2021-01-30 15:37

I\'m trying to write \"good\" python and capture a S3 no such key error with this:

session = botocore.session.get_session()
client = session.create_client(\'s3\'         


        
4条回答
  •  失恋的感觉
    2021-01-30 15:57

    Using botocore 1.5, it looks like the client handle exposes the exception classes:

    session = botocore.session.get_session()
    client = session.create_client('s3')
    try:
        client.get_object(Bucket=BUCKET, Key=FILE)
    except client.exceptions.NoSuchKey as e:
        print >> sys.stderr, "no such key in bucket"
    

提交回复
热议问题