py-googletranslation icon indicating copy to clipboard operation
py-googletranslation copied to clipboard

No translations returned when translating list of strings

Open msoutopico opened this issue 4 years ago • 0 comments
trafficstars

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):

  • OS: Ubuntu 20.04.2 LTS
  • python version: 3.8.5

msoutopico avatar Apr 06 '21 14:04 msoutopico