【发布时间】:2016-05-17 21:28:48
【问题描述】:
我已使用word2vec 生成了一个二进制文件,将生成的.bin 文件存储到我的 GCS 存储桶中,并在我的 App Engine 应用处理程序中运行以下代码:
gcs_file = gcs.open(filename, 'r')
content = gcs_file.read().encode("utf-8")
""" call word2vec with content so it doesn't need to read a file itself, as we don't have a filesystem in GAE """
失败并出现此错误:
content = gcs_file.read().encode("utf-8")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf6 in position 15: ordinal not in range(128)
如果我尝试gcs_file.read() 或gcs_file.read().decode("utf-8").encode("utf-8"),则会出现类似的解码错误。
关于如何从 GCS 读取二进制文件的任何想法?
谢谢
【问题讨论】:
-
为什么要调用encode?如果是字节,则已经编码。
-
不是你不知道的字节知道它是什么,如果它是
png那么它肯定不是已经使用编码一个字符编码。除非它被转换为Base64或UUE,但我很确定从代码和问题中也不是的情况。
标签: python google-app-engine binary google-cloud-storage word2vec