Google App Engine blobstore를 사용하여 수백 바이트에서 최대 수백KB 크기의 사용자 데이터를 저장할 수 있습니다. blob_info는 데이터 저장소 엔터티에 대한 속성으로 저장됩니다.Google App Engine blobstore 오류 : BlobNotFoundError
때때로 프로덕션 환경에서 BlobStore의 읽기는 BlobNotFoundError ('',)로 실패합니다. 예외는 세부 사항을 제공하지 않으며 실패가 발생하는 이유를 알 수 없습니다. 구글의 문서에 따르면
". BLOB 실제 Blob 저장소의 값을 참조하지 않는 경우, 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