在GAE上使用云存储的FileNotOpenedError

时间:2012-07-16 23:54:09

标签: google-app-engine google-cloud-storage

我正在尝试从远程api shell写入云存储中的文件,并看到以下内容:

s~appid> FILENAME = '/gs/test_bucket/test'

s~appid> writable_file = files.gs.create(FILENAME,
mime_type='application/octet-stream', acl='project-private')

s~appid> with files.open(writable_file, 'a') as f:
          ...     f.write('[]')
          ...
---------------------------------------------------------------------------
FileNotOpenedError                        Traceback (most recent call last)
/Users/dhruvkaranmehta/Projects/getaround3/tools/g3/shell.pyc in <module>()
      1 with files.open(writable_file, 'a') as f:
----> 2     f.write('[]')
      3

/usr/local/google_appengine/google/appengine/api/files/file.pyc in
__exit__(self, atype, value, traceback)
    288
    289   def __exit__(self, atype, value, traceback):
--> 290     self.close()
    291
    292   def write(self, data, sequence_key=None):

/usr/local/google_appengine/google/appengine/api/files/file.pyc in
close(self, finalize)
    282     request.set_filename(self._filename)
    283     request.set_finalize(finalize)
--> 284     self._make_rpc_call_with_retry('Close', request, response)
    285
    286   def __enter__(self):

/usr/local/google_appengine/google/appengine/api/files/file.pyc in
_make_rpc_call_with_retry(self, method, request, response)
    395   def _make_rpc_call_with_retry(self, method, request, response):
    396     try:
--> 397       _make_call(method, request, response)
    398     except (ApiTemporaryUnavailableError,
FileTemporaryUnavailableError):
    399

/usr/local/google_appengine/google/appengine/api/files/file.pyc in
_make_call(method, request, response, deadline)
    243     rpc.check_success()
    244   except apiproxy_errors.ApplicationError, e:
--> 245     _raise_app_error(e)
    246
    247

/usr/local/google_appengine/google/appengine/api/files/file.pyc in
_raise_app_error(e)
    186   elif (e.application_error ==
    187         file_service_pb.FileServiceErrors.FILE_NOT_OPENED):
--> 188     raise FileNotOpenedError()
    189   elif (e.application_error ==
    190         file_service_pb.FileServiceErrors.READ_ONLY):

FileNotOpenedError:

由于文件刚刚打开,这看起来很奇怪。我还看到了另一种情况,即以'a'模式打开文件会导致FinalizationError

任何其他信息都会非常有用。

谢谢!

1 个答案:

答案 0 :(得分:0)

对于第一部分,有一个功能请求来支持远程api shell中的文件api。您可以使用交互式控制台尝试相同的操作(请参阅Is there an interactive console for public/uploaded app engine apps?)。

关于您的第二个错误,documentation声明:

  

您无法打开和写入已经完成的文件。