Googletrans not detecting language

Question:

Good morning everyone,

I am using googleTrans in my code to translate a list of sentence. It worked perfectly until today. Now when I run it, it perceive everything as English and then not making any translation.
One classical code I tried to do a test:

from googletrans import Translator
translator = Translator()
results =translator.translate('हॅलो वर्ल्ड')
print(results.text)

Which is printing "हॅलो वर्ल्ड". Same with french sentences or other languages.

translation = translator.translate("Hola Mundo")
print(f"{translation.origin} ({translation.src}) --> {translation.text} ({translation.dest})")

Is giving: "Hola Mundo (en) –> Hola Mundo (en)"

My text is in different language so I cannot set one input language.

Any idea how to fix it ?

Asked By: Claire S

||

Answers:

googletrans uses not the official API. It uses the Google Translate Ajax API.
You can also read this in the docs.
If you make too many requests, especially one right after another, you will be banned.

Turn on exceptions and you will see that you get the HTTP Error 429 Too Many Requests:

>>> from googletrans import Translator
>>> translator = Translator(raise_exception=True)
>>> print(translator.translate('हॅलो वर्ल्ड').text)
Traceback (most recent call last):
  ...
Exception: Unexpected status code "429" from ['translate.googleapis.com']

What can you do? Do not make too many requests or use the official API.

Answered By: Sven Eberth