lushan88a / google_trans_new

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

json.decoder.JSONDecodeError: Extra data: line 1 column 300 (char 299) #36

Open njlester opened 3 years ago

njlester commented 3 years ago

Translating anything fails with exception "json.decoder.JSONDecodeError: Extra data: line 1 column 300 (char 299)"

LostInDarkMath commented 3 years ago

Same issue:

  File "/usr/local/lib/python3.9/site-packages/google_trans_new/google_trans_new.py", line 188, in translate
    raise e
  File "/usr/local/lib/python3.9/site-packages/google_trans_new/google_trans_new.py", line 152, in translate
    response = json.loads(response)
  File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 1962 (char 1961)

Hope you can fix this soon.

CurtisDai commented 3 years ago

Change the line 151 in google_trans_new/google_trans_new.py which is: response = (decoded_line + ']') to response = decoded_line

lntechnical2 commented 3 years ago

Same issue 😑

luke315 commented 3 years ago

151行 response = (decoded_line + ']') 导致json解析错误 修改成 response = (decoded_line) 即可

sayonari commented 3 years ago

If you want to use language detect function,

def detect(self, text):

you should fix the line 233

response = (decoded_line + ']') to response = (decoded_line)

ThiagoSousa commented 3 years ago

This solution worked for me. It should be implemented in the code in the repo and update a new version on pip, this is a major bug.

daleidenmt commented 3 years ago

When can a new release be expected? This is a major bug.

ffreemt commented 3 years ago

I refactored the translation part of google-trans-new using httpx: https://github.com/ffreemt/google-itranslate, not fully tested though.

To install via pip:

pip install itranslate

The package also provide an async version: atranslate.

kmkolasinski commented 3 years ago

Hi, thanks for fix. Are you going to release the new pip package ?

meoww commented 3 years ago

is it possible to release a new version with that fix?

NicoCaldo commented 3 years ago

same issue, waiting for the fix as I can't manually edit the package on my project

crangarita commented 3 years ago

Thanks, I edited the file manually and everything worked

bjquinniii commented 3 years ago

I refactored the translation part of google-trans-new using httpx: https://github.com/ffreemt/google-itranslate, not fully tested though.

To install via pip:

pip install itranslate

The package also provide an async version: atranslate.

Many thanks for pushing this out with the json loads issue fixed. I thought it had been incorporated into google_trans_new but even when I uninstalled/reinstalled the package, the old broken code was still in place. Your version plugged in almost seamlessly to a project where I was using google_trans_new. Only differences being in the way you call it (yes, I actually had to read your instructions) and in the way the target language is specified.

fakhruddin-ezzey commented 3 years ago

Hello all, I tried to fix by using the new version but I am getting the same error again.

I am trying to decode "mai pareshan hu" which is Hindi for "i am worried" in Django views, but I am still getting error while using the translate() function.

When user submits the form, it goes into the URL like /urlname?q="<my_submitted_text>" and receiving it at the view of respective URL. But when I receive it in views, the problem in the translate occurs again.

I tried updating the line 151 as suggested by @CurtisDai. Is there something I am doing it wrong. I appreciate any help I can get.

Thank you in advance.

YeshanMa commented 3 years ago

Change the line 151 in google_trans_new/google_trans_new.py which is: response = (decoded_line + ']') to response = decoded_line

Change the line 151 and Line 233 in google_trans_new/google_trans_new.py: response = (decoded_line + ']') to response = (decoded_line) # Note the Brackets shall be added

This solution works, confirmed on 18-Jul-2021. Thanks very much~~

image

fakhruddin-ezzey commented 3 years ago

Change the line 151 in google_trans_new/google_trans_new.py which is: response = (decoded_line + ']') to response = decoded_line

Change the line 151 and Line 233 in google_trans_new/google_trans_new.py: response = (decoded_line + ']') to response = (decoded_line) # Note the Brackets shall be added

This solution works, confirmed on 18-Jul-2021. Thanks very much~~

image

Hello @YeshanMa . Thanks for your help and time. I tried replacing it but it still doesnt work for some other reason. Still, thanks again for the help.

gowrithampi commented 3 years ago

This still doesn't work, hope it gets updated on pip soon, so that I can use google translate on some production systems easily.

yellalena commented 2 years ago

any updates, guys? getting the same error

dsorato commented 2 years ago

I'm also getting the same error. So the API is not working?

NicoCaldo commented 2 years ago

I'm also getting the same error. So the API is not working?

@YeshanMa fix worked for me. I had to modify the code of the package but since then, no issue

fakhruddin-ezzey commented 2 years ago

Hi @NicoCaldo, can you share how you did it again with the code replacement? I tried to replace the same but didnt work. Thanks in advance.

NicoCaldo commented 2 years ago

Hi @NicoCaldo, can you share how you did it again with the code replacement? I tried to replace the same but didnt work. Thanks in advance.

Change the line 151 in google_trans_new/google_trans_new.py which is: response = (decoded_line + ']') to response = decoded_line

guillejd96 commented 2 years ago

Any update? Same error here.

Mahmoud-Khorshed-DS-AI commented 2 years ago

i change in line 153 and also still the error .. any help plz

GbotemiB commented 2 years ago

I am currently working with kaggle notebook. can anyone help out on how to fix the bug from my end?

Leopoldxxx commented 2 years ago

i change in line 153 and also still the error .. any help plz

me too,Have you found any way?

kqvanity commented 2 years ago

Change the line 151 and Line 233 in google_trans_new/google_trans_new.py:

Altering it at both of these positions fixed both translation and language detection.

FlickerMi commented 1 month ago

Change the line 151 in google_trans_new/google_trans_new.py which is:更改 google_trans_new/google_trans_new.py 中的第 151 行: response = (decoded_line + ']') to  到 response = decoded_line

I committed the modified package to Pypi, use if necessary.

pypi: https://pypi.org/project/google-trans-new-flicker code: https://github.com/FlickerMi/google_trans_new