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

Google cloud storage 无法从Cloud ML Engine中的培训师应用程序下载Google云存储文件,google-cloud-storage,google-cloud-ml-engine,Google Cloud Storage,Google Cloud Ml Engine,我正在尝试从运行在Cloud ML引擎中的trainer应用程序中的云存储下载一个文件。但是,当我尝试下载该文件时,出现以下错误。 我确实可以访问云存储路径 错误: 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.d

我正在尝试从运行在Cloud ML引擎中的trainer应用程序中的云存储下载一个文件。但是,当我尝试下载该文件时,出现以下错误。 我确实可以访问云存储路径

错误:

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)
我不向客户提供任何GCP凭据,因为运行的培训师应用程序可以使用访问其他文件

tf.train.string_input_producer

任何帮助都将不胜感激。

培训师应用程序通过TensorFlow的模块访问其他文件。有一些提示,但如果要打开文件:

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

还有一份。。函数并将文件读取到字符串…,如果它们更适合您的需要。

谢谢。这很有帮助。不知道为什么我尝试的方式不起作用。