R
R
r1mple2021-06-09 21:28:44
Python
r1mple, 2021-06-09 21:28:44

Why doesn't it translate?

#-*- coding: utf-8 -*-

from Translate import Translater
import config

tr = Translater(config.API_KEY)
print(tr.translate('hello', 'ru'))

#-*- coding: utf-8 -*-
from yandex.Translater import Translater as MainTranslater
from langdetect import detect

class Translater:
    def __init__(self, APIKEY):
        self.tr = MainTranslater()
        self.tr.set_key(APIKEY)
    
    def translate(self, text, langTo):
        self.tr.set_from_lang(detect(text))
        self.tr.set_to_lang(langTo)  
        self.tr.set_text(text)
        return self.tr.translate()


Everything seems to be written correctly, but for some reason it's still an error.
raceback (most recent call last):
  File "c:/Users/Ilya/Desktop/Translator/main.py", line 7, in <module>
    print(tr.translate('hello', 'ru'))
  File "c:\Users\Ilya\Desktop\Translator\Translate.py", line 14, in translate
    return self.tr.translate()
  File "c:\users\ilya\appdata\local\programs\python\python36\lib\site-packages\yandex\Translater.py", line 209, in translate
    raise TranslaterError('Failed to translate text! {0}'.format(response.reason))
yandex.Translater.TranslaterError: Failed to translate text! Forbidden

I'm thinking maybe there is a problem with the key itself, because in Google it doesn't give anything sensible.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex F, 2021-06-10
@delvin-fil

yandex.Translater
And through Yandex and will not translate!
60c16e95de4d2039881052.png
Take this library.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question