zyddnys/manga-image-translator

[Bug]: not removing non UTF-8 characters before Youdao API call

Opened this issue · 0 comments

Issue

UTF-8 characters should be deleted before sending request to Youdao, else the request will result in 202.

如果确认应用ID和应用密钥的正确性,仍返回202,一般是编码问题。请确保翻译文本 q 为UTF-8编码.

https://ai.youdao.com/DOCSIRMA/html/trans/api/wbfy/index.html

Command Line Arguments

-m manga_translator -v --translator=youdao -l CHS -i --use-gpu

Console logs

[batch] Loading models
[batch] Running text detection
[DefaultDetector] Detection resolution: 1536x1280
[batch] Running ocr
[Model48pxOCR] prob: 0.29797518253326416 👌 fg: (153, 160, 152) bg: (249, 186, 215)

...

[batch] No pre-translation replacements made.
[batch] Running text translation
[YoudaoTranslator] Translating into Chinese (Simplified)
ERROR: [batch] InvalidServerResponse: Youdao returned invalid response: {'requestId': '382cd8df-0ed6-4647-8f81-39cc98d5e543', 'errorCode': '202', 'l': 'auto2zh-CHS'}
Are the API keys set correctly?
Traceback (most recent call last):
  File "manga-image-translator/manga_translator/__main__.py", line 99, in <module>
    loop.run_until_complete(dispatch(args))
  File "/opt/homebrew/Cellar/python@3.11/3.11.10/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "manga-image-translator/manga_translator/__main__.py", line 59, in dispatch
    await translator.translate_path(path, dest, args_dict)
  File "manga-image-translator/manga_translator/manga_translator.py", line 178, in translate_path
    if await self.translate_file(file_path, output_dest, params):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "manga-image-translator/manga_translator/manga_translator.py", line 205, in translate_file
    return await self._translate_file(path, dest, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "manga-image-translator/manga_translator/manga_translator.py", line 248, in _translate_file
    ctx = await self.translate(img, ctx)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "manga-image-translator/manga_translator/manga_translator.py", line 305, in translate
    return await self._translate(ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "manga-image-translator/manga_translator/manga_translator.py", line 470, in _translate
    ctx.text_regions = await self._run_text_translation(ctx)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "manga-image-translator/manga_translator/manga_translator.py", line 579, in _run_text_translation
    await dispatch_translation(ctx.translator,
  File "manga-image-translator/manga_translator/translators/__init__.py", line 130, in dispatch
    queries = await translator.translate('auto', tgt_lang, queries, use_mtpe)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "manga-image-translator/manga_translator/translators/common.py", line 183, in translate
    _translations = await self._translate(*self.parse_language_codes(from_lang, to_lang, fatal=True), queries)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "manga-image-translator/manga_translator/translators/youdao.py", line 66, in _translate
    raise InvalidServerResponse(f'Youdao returned invalid response: {result}\nAre the API keys set correctly?')
manga_translator.translators.common.InvalidServerResponse: Youdao returned invalid response: {'requestId': '382cd8df-0ed6-4647-8f81-39cc98d5e543', 'errorCode': '202', 'l': 'auto2zh-CHS'}
Are the API keys set correctly?