2017-08-10 47 views
0

我試圖從我的教練應用程序在雲ML引擎中運行時從雲存儲中下載文件。但是,當我嘗試下載文件時,出現以下錯誤。 我有權訪問雲存儲路徑。無法從雲ML引擎中的教練應用程序下載Google雲存儲文件

錯誤:

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憑據Client作爲訓練者應用軟件的運行可以通過訪問其他文件

tf.train.string_input_producer 

任何幫助,將不勝感激。

回答

1

培訓師應用程序通過TensorFlow的file_io模塊訪問其他文件。 This post有一些技巧,但是如果你想打開一個文件:

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

還有一個copy(..)功能和read_file_to_string(...),如果這些滿足您的需求更好。

+0

謝謝。這非常有幫助。不知道爲什麼它不符合我嘗試的方式。 –

相關問題