Saravananslb / py-googletranslation

pygoogletranslation: Free and Unlimited Google translate API for Python. Translates totally free of charge.
https://saravananslb.github.io/py-googletranslation/
MIT License
156 stars 40 forks source link

No translations returned when translating list of strings #25

Open msoutopico opened 3 years ago

msoutopico commented 3 years ago

Describe the bug No translations returned when the request is sent from a script run as a cron job.

To Reproduce I have a list of sentences, created dynamically, like: list_of_strings = ['This is one sentence.', 'This is another sentence.', 'etc.']

which I send to Google with function such:

def get_mt_of_list(list_of_strings, src_lang, dest_lang):
  try:
      translations = (translator.translate(list_of_strings, src=google_tag, dest=dest_lang))
      return [xlat.text for xlat in translations]
  except Exception:
      logging.error(Exception)
      return None

My list has 130 sentences in Croatian and a bit above 6,000 characters. I call the script with src_lang='hr' and dest_lang='en'.

Expected behavior The list of translations.

Actual behviour When I do it manually in the python interpreter, I get the list of translations. However, when this function is run in my script (called as a cron job), I get the following in my log, 70 times:

[2021-04-06 13:05:28,303] urllib3.connectionpool@connectionpool:971 DEBUG: Starting new HTTPS connection (1): translate.google.com:443
[2021-04-06 13:05:28,348] urllib3.connectionpool@connectionpool:452 DEBUG: https://translate.google.com:443 "POST /_/TranslateWebserverUi/data/batchexecute?rpcids=MkEWBc&bl=boq_translate-webserver_20201207.13_p0&soc-app=1&soc-platform=1&soc-device=1&rt=c HTTP/1.1" 200 None

I get the above 70 times, and then an exception.

The 200 at the end means the request was a success (on the level of http/s), but I get an exception, not the translations. If the API accept it or not, that I don't know.

Desktop (please complete the following information):