Amazon s3 The specified key does not exist after get_key succeeds

I use python and boto

this is my code:

key = bucket.get_key(key_name) if not key: print 'error, key does not exist' return data = key.get_contents_as_string() 

sometimes (appears randomly) I get this exception:

S3ResponseError: S3ResponseError: 404 Not found

NOTE: the file is uploaded by one server, and then immediately after that another server (located on a different continent) runs the code above.

trace:

Traceback (last last call): File /test.py, line 222, in _process_response

data = key.get_contents_as_string () File "/usr/lib/python2.6/site-packages/boto-2.1.1-py2.6.egg/boto/s3/key.py",

line 1201, in get_contents_as_string response_headers = response_headers) File "/usr/lib/python2.6/site-packages/boto-2.1.1-py2.6.egg/boto/s3/key.py",

line 1093, in get_contents_to_file response_headers = response_headers) File "/usr/lib/python2.6/site-packages/boto-2.1.1-py2.6.egg/boto/s3/key.py",

line 996, in get_file override_num_retries = override_num_retries) File "/usr/lib/python2.6/site-packages/boto-2.1.1-py2.6.egg/boto/s3/key.py",

line 211 opened by override_num_retries = override_num_retries) File "/usr/lib/python2.6/site-packages/boto-2.1.1-py2.6.egg/boto/s3/key.py",

line 165, in open_read self.resp.reason, body) S3ResponseError: S3ResponseError: 404 Not found

<Code> NoSuchKey The specified key does not exist.key_nameidhost_id

so I get the key, but then when I try to read it, I get "not found". Any ideas?

+8
python web-services amazon-s3 amazon-web-services boto
source share
1 answer

This is the expected behavior, according to the Amazon S3 Developer's Guide :

... However, the change information may not be immediately replicated through Amazon S3, and you can observe the following behaviors: the process writes a new object to Amazon S3 and immediately tries to read it. Until the change is fully distributed, Amazon S3 may report that the "key does not exist."

+8
source share

All Articles