Summary
python-docx raises:
docx.opc.exceptions.PackageNotFoundError: Package not found at '/a/b/c.docx'
on Document("/a/b/c.docx") when the file or path provided does not resolve to a ZIP archive. For diagnostic purposes it would be better to distinguish a No such file or directory condition from a file exists but is not a ZIP archive (and so not a DOCX file) condition.
Proposed
- Add a separate
os.file.isfile() test on a provided file-path before attempting to open it with zipfile. Give this a focused message like FileNotFoundError: No such file or directory: '/a/b/c.docx' so the problem is unambiguous.
- Change the
PackageNotFoundError text to more specifically indicate the file is not a zip archive.
Summary
python-docxraises:on
Document("/a/b/c.docx")when the file or path provided does not resolve to a ZIP archive. For diagnostic purposes it would be better to distinguish aNo such file or directorycondition from afile exists but is not a ZIP archive (and so not a DOCX file)condition.Proposed
os.file.isfile()test on a provided file-path before attempting to open it withzipfile. Give this a focused message likeFileNotFoundError: No such file or directory: '/a/b/c.docx'so the problem is unambiguous.PackageNotFoundErrortext to more specifically indicate the file is not a zip archive.