Writing Binary to a Word Document [closed]

风格不统一 提交于 2019-12-13 08:58:03

问题


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)

When I go to open the word document, it says there is unreadable content and cannot open the file. Appreciate any help I can get with this. By the way, I need to use DocxTemplate as my word-document template logic requires this type. Thanks in advance.

The error i am getting is:

template.write(stream_data)
TypeError: write() argument must be str, not bytes

来源:https://stackoverflow.com/questions/59078815/writing-binary-to-a-word-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!