document_binary = py.view_binary(id['id'])
#view_binary is a function that makes an API call to get the binary
#string of a document storage in a file space.It takes the ID of the
#document as the parameter and returns binary string
binary_stream = io.BytesIO()
binary_stream.write(document_binary.encode('utf-8'))
binary_stream.seek(0)
stream_data = binary_stream.read()
print(type(stream_data))
print(stream_data)
当我打开单词文档时,它说内容不可读,无法打开文件。感谢我可以从中获得的任何帮助。顺便说一下,我需要使用DocxTemplate,因为我的Word文档模板逻辑需要这种类型。预先感谢。
我得到的错误是:
template.write(stream_data)TypeError:write()参数必须为str,而不是字节