terryyin / terryyin/translate-python
DeepL translation fails
Open
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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