问题
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