S3 gives me a NoSuchKey error, even if the key exists

This is my boto3 command to get an object with a specific key from an S3 bucket:

resp = s3client.get_object(Bucket='<>-<>', Key='MzA1MjY1NzkzX2QudHh0')

It produces the following error:

botocore.errorfactory.NoSuchKey: An error occurred (NoSuchKey) when calling the GetObject operation: The specified key does not exist.

I checked in the bucket and the key really exists

enter image description here

Am I missing something or did something wrong?

+4
source share
2 answers

You have% 0A at the end of your URL; that line separator.

+4
source

Since you know that the key you have is definitely in the name of the file you are looking for, I recommend using it filterto 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

, , . , S3.

+3

Source: https://habr.com/ru/post/1680200/


All Articles