[更新]
我应该注意到这是在事务中发生的,并且这个错误是在 dev_appserver 上生成的。我没有在生产环境中测试过。这似乎不会在生产中发生。
[/更新]
我不确定我在这里做错了什么;我的代码几乎与文档示例相同。
我的代码:
filename = files.blobstore.create(mime_type='application/octet-stream')
with files.open(filename, 'a') as f:
f.write(json.dumps(oldblocks, separators=(',', ':')))
files.finalize(filename)
堆栈跟踪:
WARNING 2013-01-16 12:37:49,648 tasklets.py:409] suspended generator transaction(context.py:932) raised AttributeError('Entity' object has no attribute '_to_pb')
ERROR 2013-01-16 12:37:49,648 webapp2.py:1552] 'Entity' object has no attribute '_to_pb'
Traceback (most recent call last):
File "/home/rye/local/share/google_appengine/lib/webapp2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/home/rye/local/share/google_appengine/lib/webapp2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/home/rye/local/share/google_appengine/lib/webapp2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/home/rye/local/share/google_appengine/lib/webapp2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/home/rye/local/share/google_appengine/lib/webapp2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/home/rye/local/share/google_appengine/lib/webapp2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/home/rye/Dropbox/projects/web/voxwright/voxwright.py", line 202, in put
result = saveProject(data['id'], data['blocks'])
File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/model.py", line 3583, in inner_transactional_wrapper
return transaction(f, **ctx_options)
File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/utils.py", line 136, in positional_wrapper
return wrapped(*args, **kwds)
File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/model.py", line 3526, in transaction
return fut.get_result()
File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/tasklets.py", line 325, in get_result
self.check_success()
File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/tasklets.py", line 371, in _help_tasklet_along
value = gen.send(val)
File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/context.py", line 923, in transaction
result = callback()
File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/model.py", line 3582, in <lambda>
f = lambda: func(*args, **kwds)
File "/home/rye/Dropbox/projects/web/voxwright/voxwright.py", line 102, in saveProject
files.finalize(filename)
File "/home/rye/local/share/google_appengine/google/appengine/api/files/file.py", line 568, in finalize
f.close(finalize=True)
File "/home/rye/local/share/google_appengine/google/appengine/api/files/file.py", line 291, in close
self._make_rpc_call_with_retry('Close', request, response)
File "/home/rye/local/share/google_appengine/google/appengine/api/files/file.py", line 427, in _make_rpc_call_with_retry
_make_call(method, request, response)
File "/home/rye/local/share/google_appengine/google/appengine/api/files/file.py", line 250, in _make_call
rpc.check_success()
File "/home/rye/local/share/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 570, in check_success
self.__rpc.CheckSuccess()
File "/home/rye/local/share/google_appengine/google/appengine/api/apiproxy_rpc.py", line 156, in _WaitImpl
self.request, self.response)
File "/home/rye/local/share/google_appengine/google/appengine/api/apiproxy_stub.py", line 125, in MakeSyncCall
method(request, response)
File "/home/rye/local/share/google_appengine/google/appengine/api/files/file_service_stub.py", line 652, in _Dynamic_Close
self.open_files[filename].finalize()
File "/home/rye/local/share/google_appengine/google/appengine/api/files/file_service_stub.py", line 596, in finalize
datastore.Put(blob_info)
File "/home/rye/local/share/google_appengine/google/appengine/api/datastore.py", line 579, in Put
return PutAsync(entities, **kwargs).get_result()
File "/home/rye/local/share/google_appengine/google/appengine/api/datastore.py", line 556, in PutAsync
return _GetConnection().async_put(config, entities, local_extra_hook)
File "/home/rye/local/share/google_appengine/google/appengine/datastore/datastore_rpc.py", line 1542, in async_put
pbs = [self.__adapter.entity_to_pb(entity) for entity in entities]
File "/home/rye/local/share/google_appengine/google/appengine/ext/ndb/model.py", line 562, in entity_to_pb
pb = ent._to_pb()
AttributeError: 'Entity' object has no attribute '_to_pb'