noDRM / DeDRM_tools

DeDRM tools for ebooks
6.68k stars 290 forks source link

Key extraction from Wine fails: "installed Python not found" despite Python being installed #355

Open NightEule5 opened 1 year ago

NightEule5 commented 1 year ago

Question / bug report

NoDRM fails to extract keys from Kindle running under Wine, saying Python is not installed. I have Python 3 installed at AppData/Local/Programs/Python/Python311/, and it's on Wine's Path

Which version of Calibre are you running?

6.17

Which version of the DeDRM plugin are you running?

v10.0.3

If applicable, which version of the Kindle software are you running?

1.17.1 (44183)

Log output

    DeDRM v10.0.3: Trying to decrypt o4qj00km.azw
    Using Library AlfCrypto DLL/DYLIB/SO
    MobiDeDrm v1.1.
    Copyright © 2008-2020 The Dark Reverser, Apprentice Harper et al.
    Decrypting Kindle Format 8 ebook:
    Found 0 keys to try after 0.5 seconds
    Crypto Type is: 2
    DeDRM v10.0.3: Failed to decrypt with error: No key found in 0 PIDs tried.
    DeDRM v10.0.3: Looking for new default Kindle Key after 0.5 seconds
    wineserver: using server-side synchronization.
    002c:fixme:winediag:LdrInitializeThunk Wine TkG (staging) 8.1 is a testing version containing experimental patches.
    002c:fixme:winediag:LdrInitializeThunk Please don't report bugs about it on winehq.org and use https://github.com/Frogging-Family/wine-tkg-git/issues instead.
    0084:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
    0084:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
    0084:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
    0084:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
    No installed Python found!
    0100:fixme:kernelbase:AppPolicyGetProcessTerminationMethod FFFFFFFA, 006BFE98
    Application could not be started, or no application associated with the specified file.
    ShellExecuteEx failed: File not found.

    DeDRM v10.0.3: wine python3.exe is not python3
    Fatal Python error: init_sys_streams: can't initialize sys standard streams
    Python runtime state: core initialized
    OSError: [WinError 6] Invalid handle

    Current thread 0x00000118 (most recent call first):
      <no Python frame>
    DeDRM v10.0.3: wine python.exe is not python3
    Application could not be started, or no application associated with the specified file.
    ShellExecuteEx failed: Path not found.

    DeDRM v10.0.3: wine C:\Python27\python.exe is not python3
    DeDRM v10.0.3: Unable to find python3 executable in WINEPREFIX=""
    DeDRM v10.0.3: Ultimately failed to decrypt after 2.4 seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md
    Running file type plugin DeDRM failed with traceback:
    Traceback (most recent call last):
      File "calibre_plugins.dedrm.__init__", line 957, in KindleMobiDecrypt
        book = k4mobidedrm.GetDecryptedBook(path_to_ebook,kindleDatabases,androidFiles,serials,pids,self.starttime)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/night/.config/calibre/plugins/DeDRM.zip/k4mobidedrm.py", line 261, in GetDecryptedBook
        mb.processBook(totalpids)
      File "/home/night/.config/calibre/plugins/DeDRM.zip/mobidedrm.py", line 501, in processBook
        raise DrmException("No key found in {0:d} PIDs tried.".format(len(goodpids)))
    mobidedrm.DrmException: No key found in 0 PIDs tried.

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/usr/lib/calibre/calibre/customize/ui.py", line 187, in _run_filetype_plugins
        nfp = plugin.run(nfp) or nfp
              ^^^^^^^^^^^^^^^
      File "calibre_plugins.dedrm.__init__", line 1056, in run
        decrypted_ebook = self.KindleMobiDecrypt(path_to_ebook)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "calibre_plugins.dedrm.__init__", line 1007, in KindleMobiDecrypt
        raise DeDRMError("{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime))
    calibre_plugins.dedrm.DeDRMError: DeDRM v10.0.3: Ultimately failed to decrypt after 2.4 seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md
ElleKayEm commented 1 year ago

A workaround is to temporarily install Windows calibre/DeDRM where you have Kindle for PC. Once that's working, save and import the key to your Linux setup.

NightEule5 commented 1 year ago

Calibre doesn't launch in Wine:

There was an error initializing the bypy frozen importer:
<class 'MemoryError'>:
Traceback (most recent call last):
  File bypy-importer.py, line 416, in <module>
  File bypy-importer.py, line 361, in __init__

The only bug report for this I could find is labeled "won't fix" because "Wine isn't a supported use case": https://bugs.launchpad.net/calibre/+bug/1901594

ElleKayEm commented 1 year ago

I see the person reporting the bug says calibre 4.23 did work for them. DeDRM 10.0.3 is intended to work with that version too. If it doesn't, try DeDRM 6.8.1.

NightEule5 commented 1 year ago

It doesn't:

    DeDRM v10.0.3: Trying to decrypt siwzvl.azw
    Using Library AlfCrypto Python
    Running file type plugin DeDRM failed with traceback:
    Traceback (most recent call last):
      File "site-packages\calibre\customize\ui.py", line 172, in _run_filetype_plugins
      File "calibre_plugins.dedrm.__init__", line 1056, in run
      File "calibre_plugins.dedrm.__init__", line 944, in KindleMobiDecrypt
      File "site-packages\calibre\customize\zipplugin.py", line 185, in load_module
      File "calibre_plugins.dedrm.k4mobidedrm", line 105, in <module>
      File "site-packages\calibre\customize\zipplugin.py", line 181, in load_module
      File "calibre_plugins.dedrm.topazextract", line 246
        if debug: print("%d records in header " % nbValues, end=' ')
                                                               ^
    SyntaxError: invalid syntax
    Conversion options changed from defaults:
      read_metadata_from_opf: u'C:\\users\\night\\Temp\\calibre_msqc_6\\oy82n4.opf'
      cover: u'C:\\users\\night\\Temp\\calibre_msqc_6\\6pcoka.jpeg'
      verbose: 2
      output_profile: u'generic_eink'
    Resolved conversion options
    calibre version: 4.23.0
    {'asciiize': False,
     'author_sort': None,
     'authors': None,
     'base_font_size': 0.0,
     'book_producer': None,
     'change_justification': u'original',
     'chapter': u"//*[((name()='h1' or name()='h2') and re:test(., '\\s*((chapter|book|section|part)\\s+)|((prolog|prologue|epilogue)(\\s+|$))', 'i')) or @class = 'chapter']",
     'chapter_mark': u'pagebreak',
     'comments': None,
     'cover': u'C:\\users\\night\\Temp\\calibre_msqc_6\\6pcoka.jpeg',
     'debug_pipeline': None,
     'dehyphenate': True,
     'delete_blank_paragraphs': True,
     'disable_font_rescaling': False,
     'dont_split_on_page_breaks': False,
     'duplicate_links_in_toc': False,
     'embed_all_fonts': False,
     'embed_font_family': None,
     'enable_heuristics': False,
     'epub_flatten': False,
     'epub_inline_toc': False,
     'epub_toc_at_end': False,
     'epub_version': u'2',
     'expand_css': False,
     'extra_css': None,
     'extract_to': None,
     'filter_css': u'',
     'fix_indents': True,
     'flow_size': 260,
     'font_size_mapping': None,
     'format_scene_breaks': True,
     'html_unwrap_factor': 0.4,
     'input_encoding': None,
     'input_profile': <calibre.customize.profiles.InputProfile object at 0x00000000078E80C8>,
     'insert_blank_line': False,
     'insert_blank_line_size': 0.5,
     'insert_metadata': False,
     'isbn': None,
     'italicize_common_cases': True,
     'keep_ligatures': False,
     'language': None,
     'level1_toc': None,
     'level2_toc': None,
     'level3_toc': None,
     'line_height': 0.0,
     'linearize_tables': False,
     'margin_bottom': 5.0,
     'margin_left': 5.0,
     'margin_right': 5.0,
     'margin_top': 5.0,
     'markup_chapter_headings': True,
     'max_toc_links': 50,
     'minimum_line_height': 120.0,
     'no_chapters_in_toc': False,
     'no_default_epub_cover': False,
     'no_inline_navbars': False,
     'no_svg_cover': False,
     'output_profile': <calibre.customize.profiles.GenericEink object at 0x00000000078E8CC8>,
     'page_breaks_before': u"//*[name()='h1' or name()='h2']",
     'prefer_metadata_cover': False,
     'preserve_cover_aspect_ratio': False,
     'pretty_print': True,
     'pubdate': None,
     'publisher': None,
     'rating': None,
     'read_metadata_from_opf': u'C:\\users\\night\\Temp\\calibre_msqc_6\\oy82n4.opf',
     'remove_fake_margins': True,
     'remove_first_image': False,
     'remove_paragraph_spacing': False,
     'remove_paragraph_spacing_indent_size': 1.5,
     'renumber_headings': True,
     'replace_scene_breaks': u'',
     'search_replace': '[]',
     'series': None,
     'series_index': None,
     'smarten_punctuation': False,
     'sr1_replace': None,
     'sr1_search': None,
     'sr2_replace': None,
     'sr2_search': None,
     'sr3_replace': None,
     'sr3_search': None,
     'start_reading_at': None,
     'subset_embedded_fonts': False,
     'tags': None,
     'timestamp': None,
     'title': None,
     'title_sort': None,
     'toc_filter': None,
     'toc_threshold': 6,
     'toc_title': None,
     'transform_css_rules': '[]',
     'unsmarten_punctuation': False,
     'unwrap_lines': True,
     'use_auto_toc': False,
     'verbose': 2}
    DeDRM v10.0.3: Trying to decrypt siwzvl.azw
    DeDRM v10.0.3: Failed to decrypt with error: 'module' object has no attribute 'GetDecryptedBook'
    DeDRM v10.0.3: Looking for new default Kindle Key after 0.0 seconds
    DeDRM v10.0.3: Exception when getting default Kindle Key after 0.0 seconds
    Traceback (most recent call last):
      File "calibre_plugins.dedrm.__init__", line 969, in KindleMobiDecrypt
      File "calibre_plugins.dedrm.kindlekey", line 945, in kindlekeys
      File "calibre_plugins.dedrm.kindlekey", line 338, in getKindleInfoFiles
    TypeError: ExpandEnvironmentStrings() argument 1 must be unicode, not str
    DeDRM v10.0.3: Ultimately failed to decrypt after 0.0 seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md
    Running file type plugin DeDRM failed with traceback:
    Traceback (most recent call last):
      File "site-packages\calibre\customize\ui.py", line 172, in _run_filetype_plugins
      File "calibre_plugins.dedrm.__init__", line 1056, in run
      File "calibre_plugins.dedrm.__init__", line 1007, in KindleMobiDecrypt
    DeDRMError: DeDRM v10.0.3: Ultimately failed to decrypt after 0.0 seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md
    InputFormatPlugin: MOBI Input running
    on C:\users\night\Temp\calibre_msqc_6\siwzvl.azw
    Found KF8 MOBI of type u'standalone'
    Python function terminated unexpectedly
      (Error Code: 1)
     Traceback (most recent call last):
      File "site.py", line 114, in main
      File "site.py", line 88, in run_entry_point
      File "site-packages\calibre\utils\ipc\worker.py", line 209, in main
      File "site-packages\calibre\gui2\convert\gui_conversion.py", line 43, in gui_convert_override
      File "site-packages\calibre\gui2\convert\gui_conversion.py", line 28, in gui_convert
      File "site-packages\calibre\ebooks\conversion\plumber.py", line 1110, in run
      File "site-packages\calibre\customize\conversion.py", line 246, in __call__
      File "site-packages\calibre\ebooks\conversion\plugins\mobi_input.py", line 47, in convert
      File "site-packages\calibre\ebooks\mobi\reader\mobi8.py", line 86, in __call__
      File "site-packages\calibre\ebooks\mobi\reader\mobi6.py", line 158, in check_for_drm
    calibre.ebooks.DRMError:

6.8.1 worked and I got my keys. Thanks

noDRM commented 1 year ago

I'm not sure about the Wine / python issue, this might be some kind of problem with your setup; but the issues you had running 10.0.3 on Calibre 4.23 should now hopefully be fixed for the next version.

jszwedko commented 6 months ago

I'm having this same issue with Calibre 6.13.0 and DeDRM 10.0.3. I have python3 installed but it seems to fail to find it:

$ WINEPREFIX=/home/jesse/.wine32 wine python.exe --version
Python 3.8.10

I configured the same WINEPREFIX for the DeDRM plugin but it cannot run wine python.exe. Full output:

calibre, version 6.13.0
ERROR: Loading book failed: Failed to open the book at /home/jesse/Calibre Library/Unknown/Unknown.pdf. Click "Show details" for more info.

Failed to convert book: /home/jesse/Calibre Library/Unknown/Unknown.pdf with error:
Traceback (most recent call last):
  File "/usr/lib/calibre/calibre/customize/ui.py", line 436, in get_file_type_metadata
    mi = plugin.get_metadata(stream, ftype.lower().strip())
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/calibre/calibre/customize/builtins.py", line 323, in get_metadata
    return get_quick_metadata(stream)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/calibre/calibre/ebooks/metadata/pdf.py", line 124, in get_metadata
    raise ValueError('Could not read info dict from PDF')
ValueError: Could not read info dict from PDF
DeDRM v10.0.3: Trying to decrypt Unknown.pdf
DeDRM v10.0.3: Unknown.pdf is a PDF ebook with encryption EBX_HANDLER
DeDRM v10.0.3: Unknown.pdf is a PDF ebook (EBX) for UUID e5ce4b63-1032-44bb-bc9e-81b2df4cce77
DeDRM v10.0.3: Looking for new default Adobe Digital Editions Keys after 0.3 seconds
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Python runtime state: core initialized
OSError: [WinError 6] Invalid handle

Current thread 0x00000530 (most recent call first):
<no Python frame>
DeDRM v10.0.3: wine py.exe -3 is not python3
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Python runtime state: core initialized
OSError: [WinError 6] Invalid handle

Current thread 0x00000624 (most recent call first):
<no Python frame>
DeDRM v10.0.3: wine python3.exe is not python3
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Python runtime state: core initialized
OSError: [WinError 6] Invalid handle

Current thread 0x00000610 (most recent call first):
<no Python frame>
DeDRM v10.0.3: wine python.exe is not python3
wine: failed to open "C:\\Python27\\python.exe": c0000135
DeDRM v10.0.3: wine C:\Python27\python.exe does not exist
DeDRM v10.0.3: Unable to find python3 executable in WINEPREFIX="/home/jesse/.wine32"
DeDRM v10.0.3: Finished after 2.5 seconds
Syntax Error: Couldn't find the 'EBX_HANDLER' security handler
pdfinfo errored out with return code: 1
InputFormatPlugin: PDF Input running
on /home/jesse/Calibre Library/Unknown/Unknown.pdf
Failed to run pipe worker with command: from calibre.srv.render_book import viewer_main; viewer_main()
Traceback (most recent call last):
  File "/usr/bin/calibre-parallel", line 21, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/lib/calibre/calibre/utils/ipc/worker.py", line 196, in main
    exec(sys.argv[-1])
  File "<string>", line 1, in <module>
  File "/usr/lib/calibre/calibre/srv/render_book.py", line 821, in viewer_main
    render_for_viewer(*args)
  File "/usr/lib/calibre/calibre/srv/render_book.py", line 812, in render_for_viewer
    return render(
           ^^^^^^^
  File "/usr/lib/calibre/calibre/srv/render_book.py", line 789, in render
    book_fmt, opfpath, input_fmt = extract_book(pathtoebook, output_dir, log=default_log)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/calibre/calibre/ebooks/oeb/iterator/book.py", line 62, in extract_book
    pathtoopf = plumber.input_plugin(inf,
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/calibre/calibre/customize/conversion.py", line 242, in __call__
    ret = self.convert(stream, options, file_ext,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/calibre/calibre/ebooks/conversion/plugins/pdf_input.py", line 51, in convert
    pdftohtml(os.getcwd(), stream.name, options.no_images)
  File "/usr/lib/calibre/calibre/ebooks/pdf/pdftohtml.py", line 83, in pdftohtml
    raise ConversionError('pdftohtml failed with return code: %d\n%s' % (ret, out))
calibre.ebooks.ConversionError: pdftohtml failed with return code: 1
Syntax Error: Couldn't find the 'EBX_HANDLER' security handler
jszwedko commented 6 months ago

I tried the recommendation on https://github.com/noDRM/DeDRM_tools/issues/81 to use Calibre under Wine (version 3.48 which is the last one that works on Windows 7) and DeDRM 6.8.1 but that combination seemed to result in Calibre not even running the plugin on the file when opening it (in this case a PDF that needs keys from Adobe Digital Editions).

ElleKayEm commented 6 months ago

Suggest looking at the DeACSM plugin which replaces ADE.

https://www.mobileread.com/forums/showthread.php?t=341975

jszwedko commented 6 months ago

Suggest looking at the DeACSM plugin which replaces ADE.

https://www.mobileread.com/forums/showthread.php?t=341975

You (and the author of libgourou) have just made my life a whole lot simpler! Thank you! It worked like a charm. I ran the libgourou tools locally rather than using the plugin, but I'll try that next.