diff options
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/docx/files.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/mammoth/docx/files.py b/mammoth/docx/files.py index ce557f6..bde488d 100644 --- a/mammoth/docx/files.py +++ b/mammoth/docx/files.py @@ -22,10 +22,12 @@ class Files(object): if _is_absolute(uri): return contextlib.closing(urlopen(uri)) elif self._base is not None: - path = os.path.join(self._base, uri) - if not os.path.exists(path): - raise InvalidFileReferenceError("could not find external image '{0}' from document directory '{1}'".format(uri, self._base)) - return open(path, "rb") + try: + return open(os.path.join(self._base, uri), "rb") + except IOError as error: + message = "could not open external image '{0}' from document directory '{1}'\n{2}".format( + uri, self._base, str(error)) + raise InvalidFileReferenceError(message) else: raise InvalidFileReferenceError("could not find external image '{0}', fileobj has no name".format(uri)) |
