S3 BOTO returns NoSuchKey when trying to copy an existing key

I create a key on S3.

mykey.exists() returns true

mykey.get_contents_to_filename() generates the correct file

But:

mykey.copy('bucket', '/backup/file')

returns: NoSuchKey The Specified key does not exist. Key = mykey NoSuchKey The Specified key does not exist. Key = mykey

Looks like I'm using boto 2.0b4 If the key exists, why am I getting a NoSuchKey error? What am I missing?

edit: change the backslash in the key name to the assumptions that I actually use

+4
source share
2 answers

I have a theory that since amazon s3 is ultimately serial, one request could see the key (.exists () == True), while the other request ends up on another s3 server that does not yet know the new key (consistent reading is a difficulty with eventually consistent datastores. This is a known behavior for s3 with a mark followed by a / get head. I expect it to be saved for copy as well.) After a usually short (but indefinite) time period all requests will see your key. This is usually just a second or two. Put a 30 second timeout in your code between the exists () check and the copy. Is this still happening?

The problem is described here: https://forums.aws.amazon.com/thread.jspa?threadID=21634&tstart=0 )

+1
source

I think you might have a problem with your key name. The baskslash characters in the string '\ backup \ file' are actually interpreted as escapes strings, so '\ b' is replaced by the ASCII backspace character, and '\ f' is interpreted as ASCII formfeed (see this for more details). Although this is probably not what you intended, it should really work, but there was an error in crowding out the key names in boto2.0b4 (which is now fixed in github-master), which prevents it from working.

If you really want your key name to be "\ backup \ file", try specifying it as r '\ backup \ file' in Python. This treats it as a raw string, and branch processing will not be performed.

0
source

All Articles