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

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

Open
njlester opened this issue Jun 29, 2021 · 28 comments
Open

Comments

@njlester
Copy link

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

@LostInDarkMath
Copy link

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/[email protected]/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/[email protected]/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
Copy link

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

@lntechnical2
Copy link

Same issue 😑

@luke315
Copy link

luke315 commented Jun 30, 2021

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

@sayonari
Copy link
Contributor

sayonari commented Jun 30, 2021

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

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.

mesnitu added a commit to mesnitu/google_trans_new that referenced this issue Jun 30, 2021
@daleidenmt
Copy link

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

@ffreemt
Copy link

ffreemt commented Jul 4, 2021

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

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

@meoww
Copy link

meoww commented Jul 6, 2021

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

@NicoCaldo
Copy link

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

@crangarita
Copy link

Thanks, I edited the file manually and everything worked

@bjquinniii
Copy link

bjquinniii commented Jul 15, 2021

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

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

YeshanMa commented Jul 18, 2021

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

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

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

any updates, guys? getting the same error

@dsorato
Copy link

dsorato commented Nov 17, 2021

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

@NicoCaldo
Copy link

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

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

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

Any update? Same error here.

@Mahmoud-Khorshed-DS-AI
Copy link

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

@GbotemiB
Copy link

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

@Leopoldxxx
Copy link

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

me too,Have you found any way?

@kqvanity
Copy link

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

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

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