无法从Cloud ML Engine中的培训师应用程序下载Google云端存储文件

时间:2017-08-10 02:05:42

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

我尝试从Cloud ML引擎中运行的培训师应用程序下载Cloud Storage中的文件。但是,当我尝试下载文件时,我收到以下错误。 我可以访问云存储路径。

错误:

blob.download_to_filename(destination_file_name) File "/root/.local/lib/python2.7/site-packages/google/cloud/storage/blob.py", line 482, in download_to_filename self.download_to_file(file_obj, client=client) File "/root/.local/lib/python2.7/site-packages/google/cloud/storage/blob.py", line 464, in download_to_file self._do_download(transport, file_obj, download_url, headers) File "/root/.local/lib/python2.7/site-packages/google/cloud/storage/blob.py", line 418, in _do_download download.consume(transport) File "/root/.local/lib/python2.7/site-packages/google/resumable_media/requests/download.py", line 101, in consume self._write_to_stream(result) File "/root/.local/lib/python2.7/site-packages/google/resumable_media/requests/download.py", line 62, in _write_to_stream with response: AttributeError: __exit__

以下是下载GCS文件的代码:

  storage_client = storage.Client()
  bucket = storage_client.get_bucket(bucket_name)
  blob = bucket.blob(key)
  blob.download_to_filename(destination_file_name)

我没有向Client提供任何GCP凭据,因为运行的培训师应用程序可以使用

访问其他文件
tf.train.string_input_producer

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:1)

教练应用程序通过TensorFlow的file_io模块访问其他文件。 This post有一些提示,但如果您要打开文件:

with file_io.FileIO("gs://my_bucket/myfile") as f:
  f.read()

还有一个copy(..)功能和read_file_to_string(...),如果这些功能更符合您的需求。

相关问题