我使用Google App Engine blobstore来保存一组用户数据 - 从几百字节到几百KB的大小。 blob_info作为数据存储实体上的属性保存。Google App Engine blobstore错误:BlobNotFoundError
偶尔在生产中,blobstore的读取操作将失败,并显示BlobNotFoundError('',)。这个例外没有提供任何细节,我不知道为什么发生故障。
根据谷歌的文档:
“如果斑点确实不是指实际的Blobstore值,则fetch_data提出了BlobNotFoundError。” https://developers.google.com/appengine/docs/python/blobstore/functions#fetch_data
“fetch_data()函数找不到与给定的BlobInfo或BlobKey值相对应的Blobstore值。” https://developers.google.com/appengine/docs/python/blobstore/exceptions#BlobNotFoundError
最令人费解的是,这些故障是间歇性的。
下面是我读取/写入blobstore的代码。只有在blob_info(从数据存储读取)不是None时才尝试读取。
有什么建议吗?
def read(blob_info):
blob_reader = blobstore.BlobReader(blob_info.key(), buffer_size=358400)
try:
data = blob_reader.read()
finally:
blob_reader.close()
return data
def write(data, mime_type):
file_name = files.blobstore.create(mime_type=mime_type)
with files.open(file_name, 'a') as f:
f.write(data)
files.finalize(file_name)
blob_key = files.blobstore.get_blob_key(file_name)
# This is a hack to handle an apparent GAE delay synchronizing the blobstore
for i in range(1,3):
if blob_key:
break
else:
time.sleep(0.05)
blob_key = files.blobstore.get_blob_key(file_name)
new_blob_info = blobstore.BlobInfo.get(str(blob_key))
return new_blob_info