Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning on opening ebook #307

Closed
aozgaa opened this issue Apr 20, 2024 · 2 comments
Closed

Warning on opening ebook #307

aozgaa opened this issue Apr 20, 2024 · 2 comments

Comments

@aozgaa
Copy link

aozgaa commented Apr 20, 2024

Given this sample code:

from ebooklib import epub
epub_file = "somefile.epub"
book = epub.read_epub(epub_file, {"ignore_ncx": True})

I get these warnings:

c:\Users\...\venv\lib\site-packages\ebooklib\epub.py:1423: FutureWarning: This search incorrectly ignores the root element, and will be fixed in a future version.  If you rely on the current behaviour, change it to './/xmlns:rootfile[@media-type]'
  for root_file in tree.findall('//xmlns:rootfile[@media-type]', namespaces={'xmlns': NAMESPACES['CONTAINERNS']}):

And here is a stack trace:

  File "c:\Users\...\myscript.py", line 9, in extract_paragraphs
    book = epub.read_epub(epub_file, {"ignore_ncx": True})
  File "c:\Users\...\venv\lib\site-packages\ebooklib\epub.py", line 1768, in read_epub
    book = reader.load()
  File "c:\Users\...\venv\lib\site-packages\ebooklib\epub.py", line 1410, in load
    self._load()
  File "c:\Users\...\venv\lib\site-packages\ebooklib\epub.py", line 1721, in _load
    self._load_container()
  File "c:\Users\...\venv\lib\site-packages\ebooklib\epub.py", line 1423, in _load_container
    for root_file in tree.findall('//xmlns:rootfile[@media-type]', namespaces={'xmlns': NAMESPACES['CONTAINERNS']}):

As the warning indicates, this error can be fixed by making the actual behavior explicit by modifying epub.py:1423 to add a . at the beginning of the xpath. But I am not sure if this behavior is intended.

Platform: Windows 10
Python version : '3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]'

@aerkalov
Copy link
Owner

Thanks! I merged the PR where this is fixed.

@lyz-code
Copy link

lyz-code commented Aug 9, 2024

Hi @aerkalov can you please make a release on Pypi with the fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants