S3 giving me NoSuchKey error even when the key exists

前端 未结 2 2100
温柔的废话
温柔的废话 2021-02-13 01:44

This is my boto3 command for getting the object with a specific key from an S3 bucket:

resp = s3client.get_object(Bucket=\'<>-<>\', Key=\'MzA1MjY1Nzkz         


        
2条回答
  •  庸人自扰
    2021-02-13 02:01

    Since you know the key that you have is definitely in the name of the file you are looking for, I recommend using a filter to get objects with names with your key as their prefix.

    s3 = boto3.resource('s3')
    bucket = s3.Bucket('cypher-secondarybucket')
    for obj in bucket.objects.filter(Prefix='MzA1MjY1NzkzX2QudHh0'):
        print obj.key
    

    When you run this code, you will get the key names of all the files that start with your key. This will help you find out what your file is exactly called on S3.

提交回复
热议问题