Skip to content

DeepL translation fails #103

@BenisonSam

Description

@BenisonSam
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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions