bookfere / Ebook-Translator-Calibre-Plugin

A Calibre plugin to translate ebook into a specified language.
https://translator.bookfere.com
GNU General Public License v3.0
1.54k stars 102 forks source link

[Bug report] Translation keep failing #303

Closed nemelu closed 1 month ago

nemelu commented 1 month ago

Basic information Hello, I keep getting this error no matter what book I translate or which translation engine I use.

Describe the bug Every translation job fails and shows this stack trace:

Error: Traceback (most recent call last):
  File "calibre_plugins.ebook_translator.lib.translation", line 136, in _translate_text
    translation = self.translator.translate(text)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "calibre_plugins.ebook_translator.engines.google", line 53, in translate
    return self.get_result(
           ^^^^^^^^^^^^^^^^
  File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
    raise Exception(
Exception: Can not parse returned response. Raw data: 

Traceback (most recent call last):
  File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
    br.open(request)
  File "/usr/lib/python3.12/site-packages/mechanize/_mechanize.py", line 257, in open
    return self._mech_open(url_or_request, data, timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mechanize/_mechanize.py", line 287, in _mech_open
    response = UserAgentBase.open(self, request, data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mechanize/_opener.py", line 193, in open
    response = urlopen(self, req, data)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mechanize/_urllib2_fork.py", line 425, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mechanize/_urllib2_fork.py", line 414, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mechanize/_urllib2_fork.py", line 1283, in https_open
    return self.do_open(conn_factory, req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mechanize/_urllib2_fork.py", line 1196, in do_open
    h = http_class(host_port, timeout=req.timeout)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: HTTPSConnection.__init__() got an unexpected keyword argument 'key_file'
══════════════════════════════════════
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 215, in main
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/calibre/calibre/utils/ipc/worker.py", line 150, in arbitrary_n
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "calibre_plugins.ebook_translator.lib.conversion", line 242, in convert_item
  File "calibre_plugins.ebook_translator.lib.conversion", line 86, in convert_book
  File "/usr/lib/calibre/calibre/ebooks/conversion/plumber.py", line 1294, in run
    self.output_plugin.convert(self.oeb, self.output, self.input_plugin,
  File "calibre_plugins.ebook_translator.lib.conversion", line 73, in convert
  File "calibre_plugins.ebook_translator.lib.translation", line 263, in handle
Exception: Translation failed.
1Jack2 commented 1 month ago

I'm having a similar issue.

When testing any translation engine

raceback (most recent call last):
  File "calibre_plugins.ebook_translator.components.engine", line 67, in translate_text
    translation = self.translator.translate(text)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "calibre_plugins.ebook_translator.engines.google", line 53, in translate
    return self.get_result(
           ^^^^^^^^^^^^^^^^
  File "calibre_plugins.ebook_translator.engines.base", line 210, in get_result
    raise Exception(
Exception: 无法解析返回的响应。原始数据:

Traceback (most recent call last):
  File "calibre_plugins.ebook_translator.engines.base", line 197, in get_result
    br.open(request)
  File "/usr/lib/python3.12/site-packages/mechanize/_mechanize.py", line 257, in open
    return self._mech_open(url_or_request, data, timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mechanize/_mechanize.py", line 287, in _mech_open
    response = UserAgentBase.open(self, request, data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mechanize/_opener.py", line 193, in open
    response = urlopen(self, req, data)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mechanize/_urllib2_fork.py", line 425, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mechanize/_urllib2_fork.py", line 414, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mechanize/_urllib2_fork.py", line 1283, in https_open
    return self.do_open(conn_factory, req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mechanize/_urllib2_fork.py", line 1196, in do_open
    h = http_class(host_port, timeout=req.timeout)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: HTTPSConnection.__init__() got an unexpected keyword argument 'key_file'
bookfere commented 1 month ago

The error information indicates that your Calibre is using an external Python library, which may have caused many problems. I suggest you follow the installation instructions provided by Calibre to install a version of Calibre that contains a built-in Python. This may help resolve the issue.

nemelu commented 1 month ago

I installed Calibre from the system package manager. I don't want to installed it manually.

The problem is that Python 3.12 deprecated the key_file parameter in http.client.HTTPSConnection but the package mechanize that your plugin depends on is still using it.

So, I guess I will have to wait until they fix that.

bookfere commented 1 month ago

Your Calibre is not a self-contained version, so the plugin just depends on the mechanize package you installed.

From the the issue of mechanize, this is a bug that exists in versions lower than v0.4.10. Fortunately, the issue has been addressed in version v0.4.10. Therefore, you need to upgrade mechanize to the latest version to resolve the issue.

nemelu commented 1 month ago

Thank you for the clarification. Sorry for wasting your time. Now I just need to wait for the package update.