lushan88a / google_trans_new

A free and unlimited python API for google translate.
MIT License
393 stars 170 forks source link

google trans new not working, causing jsonDecodeError #46

Open ghost opened 3 years ago

ghost commented 3 years ago

it was working around one month ago. but suddenly it is showing json loading error


JSONDecodeError Traceback (most recent call last)

in 1 from google_trans_new import google_translator 2 translator = google_translator() ----> 3 translate_text = translator.translate('สวัสดีจีน',lang_tgt='en') 4 print(translate_text) ~\anaconda3\lib\site-packages\google_trans_new\google_trans_new.py in translate(self, text, lang_tgt, lang_src, pronounce) 186 return [sentences, pronounce_src, pronounce_tgt] 187 except Exception as e: --> 188 raise e 189 r.raise_for_status() 190 except requests.exceptions.ConnectTimeout as e: ~\anaconda3\lib\site-packages\google_trans_new\google_trans_new.py in translate(self, text, lang_tgt, lang_src, pronounce) 150 try: 151 response = (decoded_line + ']') --> 152 response = json.loads(response) 153 response = list(response) 154 response = json.loads(response[0][2]) ~\anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 346 parse_int is None and parse_float is None and 347 parse_constant is None and object_pairs_hook is None and not kw): --> 348 return _default_decoder.decode(s) 349 if cls is None: 350 cls = JSONDecoder ~\anaconda3\lib\json\decoder.py in decode(self, s, _w) 338 end = _w(s, end).end() 339 if end != len(s): --> 340 raise JSONDecodeError("Extra data", s, end) 341 return obj 342 JSONDecodeError: Extra data: line 1 column 343 (char 342)
Namyalg commented 3 years ago

I am facing the same issue. The code snippet on the page doesn't work either. Is there a fix to this issue ?

Locally the changes made to the line 155 in the file google_trans_new/google_trans_new.py works, but I am using the package as a dependency on Heroku, the error still persists there

michalis001 commented 3 years ago

not working for me either

braindevices commented 3 years ago

does not work at all

erikjamesmason commented 3 years ago

@Namyalg, can you specify your fix in google_trans_new.py?

Namyalg commented 3 years ago

Hi, @erikjamesmason , I followed this issue https://github.com/lushan88a/google_trans_new/issues/36, the third comment seemed to solve my problem locally

erikjamesmason commented 3 years ago

@Namyalg awesome, thank you very much!

simranbhoneja commented 2 years ago

google translator not working It's showing this error, tried the solution given above but still the same error persists

Traceback (most recent call last): File "D:\PYTHON PROJECT\voice_translator.py", line 2, in from google_trans_new import google_translator File "C:\Python310\lib\site-packages\google_trans_new__init__.py", line 7, in
from .google_trans_new import google_translator File "C:\Python310\lib\site-packages\google_trans_new\google_trans_new.py", line 4, in import json, requests, random, re ModuleNotFoundError: No module named 'requests'

Hope to get an alternative solution soon that works! Thankyou in advance :)

nettnikl commented 2 years ago

Hey guys, having the same problem. As a workaround, do the following: Change line 156 in file /lib/python3.10/site-packages/google_trans_new/google_trans_new.py, (or wherever your lib is installed) from response = (decoded_line + ']') to response = (decoded_line + '')

EDIT: Whoops, that was already recommended in the other issue, sorry.

GbotemiB commented 2 years ago

I also encounted the json error. it is yet to still be fixed.

I was able to use https://github.com/nidhaloff/deep-translator to solve my problem.

zhiying987 commented 2 years ago

Hey guys, having the same problem. As a workaround, do the following: Change line 156 in file /lib/python3.10/site-packages/google_trans_new/google_trans_new.py, (or wherever your lib is installed) from response = (decoded_line + ']') to response = (decoded_line + '')

EDIT: Whoops, that was already recommended in the other issue, sorry.

Anaconda do it as you sad ,but not work, can you help?

nettnikl commented 2 years ago

Anaconda do it as you sad ,but not work, can you help?

Sure, if you describe your issue further, i can see if i can help

carolineylf commented 2 years ago

Anaconda do it as you sad ,but not work, can you help?

Sure, if you describe your issue further, i can see if i can help

Hi, when I use your method to delete ] , anaconda doesn't work. It fails to delete ].

kwonder0926 commented 2 years ago

Hey guys, having the same problem. As a workaround, do the following: Change line 156 in file /lib/python3.10/site-packages/google_trans_new/google_trans_new.py, (or wherever your lib is installed) from response = (decoded_line + ']') to response = (decoded_line + '')

EDIT: Whoops, that was already recommended in the other issue, sorry.

Thank you. It's working now