I've been using a Google Translate API to translate automatically a couple of words, this has been working fine for a couple of months but 2-3 days ago I've started to getting problems because this snippet was raising an error.
Code:
from google_trans_new import google_translator
translator = google_translator()
print(status) #light rain
translate_text = translator.translate(status, lang_tgt='pt')
print(translate_text) #chuva leve
Error
File "bot.py", line 74, in checkBadConditions
translate_text = translator.translate(status, lang_tgt='pt')
File "/home/pi/.local/lib/python3.7/site-packages/google_trans_new/google_trans_new.py", line 188, in translate
raise e
File "/home/pi/.local/lib/python3.7/site-packages/google_trans_new/google_trans_new.py", line 152, in translate
response = json.loads(response)
File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.7/json/decoder.py", line 340, in decode
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 358 (char 357)
I've also tried to translate_text = translator.translate(status, lang_src='en', lang_tgt='pt')
and it didn't work either
Was there any update? What am I doing wrong
It seems to be an error from the package google-trans-new
that is known and already corriged. (Check this discussion for more information).
A new version of the module with the bugfix hasn't been released to pip yet. So you have to manually do the modification or wait for the newt version to be released.