Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google trans new not working, causing jsonDecodeError #46

Open
ghost opened this issue Jul 29, 2021 · 13 comments
Open

google trans new not working, causing jsonDecodeError #46

ghost opened this issue Jul 29, 2021 · 13 comments

Comments

@ghost
Copy link

ghost commented Jul 29, 2021

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)

@ghost ghost changed the title google trans new not working google trans new not working, causing jsonDecodeError Jul 29, 2021
@Namyalg
Copy link

Namyalg commented Jul 31, 2021

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
Copy link

not working for me either

@braindevices
Copy link

does not work at all

@erikjamesmason
Copy link

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

@Namyalg
Copy link

Namyalg commented Aug 16, 2021

Hi, @erikjamesmason , I followed this issue #36, the third comment seemed to solve my problem locally

@erikjamesmason
Copy link

@Namyalg awesome, thank you very much!

@simranbhoneja
Copy link

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
Copy link

nettnikl commented Mar 20, 2022

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
Copy link

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
Copy link

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
Copy link

nettnikl commented Apr 2, 2022

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
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants