我有一个非常简单的功能,可以读取谷歌云存储文本文件。
def readFileFromBucket(filename):
storage_client = storage.Client()
bucket = storage_client.get_bucket('<mybucket>')
blob = bucket.get_blob(filename)
return blob.download_as_string()
这似乎对其他人有用。但就我而言,我得到了:
> /usr/local/envs/py2env/lib/python2.7/site-packages/google/resumable_media/requests/download.pyc
> in _write_to_stream(self, response)
> 115 else:
> 116 md5_hash = hashlib.md5()
> --> 117 with response:
> 118 # NOTE: This might "donate" ``md5_hash`` to the decoder and replace
> 119 # it with a ``_DoNothingHash``.
>
> AttributeError: __exit__
答案 0 :(得分:0)
我有同样的问题,我不知道如何解决它。 无论如何,这里有一个解决方法:
from tensorflow.python.lib.io import file_io
with file_io.FileIO("gs://<BUCKET>/file.txt", "rb") as f:
text = f.readlines()