terryyin / terryyin/translate-python

DeepL translation fails

Open
#103 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
759
Forks
152
PR merge metrics
No merged PRs in 30d

Description

from translate import Translator
translator = Translator(provider='deepl', from_lang='DE', to_lang='EN',
                        secret_access_key='<secret_access_key>')
translator.translate('Ich bin Max Mustermann')

Error Message:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Input In [81], in <cell line: 1>()
----> 1 translator.translate('Ich bin Max Mustermann'')

File C:\devtools\Python\Anaconda3Win\envs\ismll\lib\site-packages\translate\translate.py:45, in Translator.translate(self, text)
     42     return text
     44 text_list = wrap(text, TRANSLATION_API_MAX_LENGHT, replace_whitespace=False)
---> 45 return ' '.join(self.provider.get_translation(text_wraped) for text_wraped in text_list)

File C:\devtools\Python\Anaconda3Win\envs\ismll\lib\site-packages\translate\translate.py:45, in <genexpr>(.0)
     42     return text
     44 text_list = wrap(text, TRANSLATION_API_MAX_LENGHT, replace_whitespace=False)
---> 45 return ' '.join(self.provider.get_translation(text_wraped) for text_wraped in text_list)

File C:\devtools\Python\Anaconda3Win\envs\ismll\lib\site-packages\translate\providers\deepl.py:48, in DeeplProvider.get_translation(self, text)
     45 if "error" in data:
     46     raise TranslationError(data["error"]["message"])
---> 48 return data["translations"][0]["text"]

KeyError: 'translations'

Can't figure out what's wrong. The API URL seems to be fine here!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with translate/providers/deepl.py, especially the API URL mentioned at line 18 and get_translation near line 48, then reproduce the supplied Translator example. Inspect the returned response when the translations key is absent; done should mean the reported DeepL failure is handled or clearly reported instead of producing an unexplained KeyError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.