noDRM / DeDRM_tools

DeDRM tools for ebooks
7.01k stars 313 forks source link

ValueError: decoding with 'hex' codec failed (ValueError: string argument should contain only ASCII characters) #109

Open FKuerten opened 2 years ago

FKuerten commented 2 years ago

Question / bug report

Trying to import ebup from Tolino, get this exception in console. I tried to remove personal information from the log, but please advise if I removed too much. (I have not yet been able to remove any drm yet)

Which version of Calibre are you running?

5.12.0

Which version of the DeDRM plugin are you running?

v10.0.3

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

No response

Log output

DeDRM v10.0.3: Trying to decrypt *************.epub
DeDRM v10.0.3: Verifying zip archive integrity
DeDRM v10.0.3: ************.epub is a secure Adobe Adept ePub for UUID *************
Running file type plugin DeDRM failed with traceback:
Traceback (most recent call last):
  File "/usr/lib/python3.9/encodings/hex_codec.py", line 19, in hex_decode
    return (binascii.a2b_hex(input), len(input))
ValueError: string argument should contain only ASCII characters

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/calibre/calibre/customize/ui.py", line 172, in _run_filetype_plugins
    nfp = plugin.run(nfp) or nfp
  File "calibre_plugins.dedrm.__init__", line 1067, in run
    decrypted_ebook = self.ePubDecrypt(path_to_ebook)
  File "calibre_plugins.dedrm.__init__", line 533, in ePubDecrypt
    userkey = codecs.decode(userkeyhex, 'hex')
ValueError: decoding with 'hex' codec failed (ValueError: string argument should contain only ASCII characters)
ElleKayEm commented 2 years ago

Try going into DeDRM's customization and delete the Adobe Digital Editions key. Then restart calibre and re-add the book to see if ADE can automatically retrieve the correct key.

This is assuming ADE used to download the book is authorized with your Adobe ID and on the same user and machine as calibre with DeDRM.

andrisengelis commented 2 years ago

@ElleKayEm steps worked for me. I was experiencing the same error but from another epub provider for ADE content. Thanks

noDRM commented 2 years ago

Partially fixed with 9a11f480b527e3d1064b890b1b5043e1c5363957.

The general issue of a key being corrupted for whatever reason can only be fixed by re-importing (as it was the case here), but the plugin also shouldn't throw an exception and stop trying subsequent keys, this bug is fixed with this commit. With this bug fixed the plugin would probably have attempted to re-import the ADE key automatically.

Closing the issue as it seems to be resolved.

notEthan commented 2 years ago

I am relieved to have found this and fixed the same issue. thanks @ElleKayEm

noDRM commented 2 years ago

Re-opening this issue for now. There seems to be a bug in the plugin that sometimes causes malformed Adobe keys to be written to the config JSON. The fix in 9a11f480b527e3d1064b890b1b5043e1c5363957 just made it no longer crash when encountering such a malformed key, but the real fix would be not writing malformed keys.

I've received logs (and the malformed key) from one of the affected users so I should be able to test this myself and implement a real fix soon-ish.

xinluh commented 2 years ago

I'm getting the same error, except reloading/restarting doesn't solve the problem (the key is still corrupted when I look at the dedrm.json file). Loading the key manually exported by DeACSM plugin worked for me though.