Accessing Word Documents in Dash

I am working on a project where I need to access a word document to the user. I am trying to use the docx package to do this, but I have ran into trouble accessing the file. Here is the start of my update_output function after the callback.

def update_output(contents, filename):
if filename is not None:

    decoded = base64.b64decode(contents)
    file = io.BytesIO(decoded)
    f = open(file, 'rb')
    document = Document(f)
    f.close()

Dash gives me this error: TypeError: expected str, bytes or os.PathLike object, not BytesIO
I am confused because in the docx documentation it says, “In practice this means you can pass an open file or StringIO/BytesIO stream object to open or save a document like so”. Docx claims it is meant for bytesIO but dash throws an error saying it can’t be BytesIO. If someone knows how to fix this please let me know, or if there is an unrelated better way to do this I am all ears. Thanks!

Could your problem be with with the open(…) ?

This code fails with that message:

import io
file = io.BytesIO(b"some initial binary data: \x00\x01")
f = open(file, 'rb')

I’ve not used docx but it sounds like maybe you can just pass file directly to Document() ?