Skip to content

docs: mention 'rb' needed to get readable ZipFile file object #283

@paolopiace

Description

@paolopiace

It works OK with:
wdocx = Document("wfile.docx")

It fails with:
fobj = open("wfile.docx",'r')
wdocx = Document(fobj)

Error Log:
File "/usr/local/lib/python3.5/site-packages/python_docx-0.8.5-py3.5.egg/docx/api.py", line 25, in Document
document_part = Package.open(docx).main_document_part
File "/usr/local/lib/python3.5/site-packages/python_docx-0.8.5-py3.5.egg/docx/opc/package.py", line 116, in open
pkg_reader = PackageReader.from_file(pkg_file)
File "/usr/local/lib/python3.5/site-packages/python_docx-0.8.5-py3.5.egg/docx/opc/pkgreader.py", line 32, in from_file
phys_reader = PhysPkgReader(pkg_file)
File "/usr/local/lib/python3.5/site-packages/python_docx-0.8.5-py3.5.egg/docx/opc/phys_pkg.py", line 101, in init
self._zipf = ZipFile(pkg_file, 'r')
File "/usr/local/lib/python3.5/zipfile.py", line 1026, in init
self._RealGetContents()
File "/usr/local/lib/python3.5/zipfile.py", line 1093, in _RealGetContents
raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions