terryyin / translate-python

Online translation as a Python module & command line tool. No key, no authentication needed.
MIT License
728 stars 153 forks source link

DeepL translation fails #103

Open BenisonSam opened 1 year ago

BenisonSam commented 1 year ago
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!