From 36e9d3ddca904e6e8abd4a99e5ac756daa312c3c Mon Sep 17 00:00:00 2001 From: cosmos223 Date: Mon, 25 Aug 2025 13:00:35 +0900 Subject: [PATCH] Fix logic for retrieving opf_file --- ebooklib/epub.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ebooklib/epub.py b/ebooklib/epub.py index edaf40b..fc81e85 100644 --- a/ebooklib/epub.py +++ b/ebooklib/epub.py @@ -1448,8 +1448,18 @@ def _load_container(self): for root_file in tree.findall('.//xmlns:rootfile[@media-type]', namespaces={'xmlns': NAMESPACES['CONTAINERNS']}): if root_file.get('media-type') == 'application/oebps-package+xml': - self.opf_file = root_file.get('full-path') + opf_file = root_file.get('full-path') + + try: + s = self.read_file(opf_file) + except KeyError: + continue + + self.opf_file = opf_file self.opf_dir = zip_path.dirname(self.opf_file) + + if self.opf_file == '': + raise EpubException(-1, 'Can not find container file') def _load_metadata(self): container_root = self.container.getroot()