lushan88a / google_trans_new

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

the translator doesn't work. Try to solve it and record it #43

Closed rggu2zr closed 3 years ago

rggu2zr commented 3 years ago

install

pip3 install google-trans-new

translate

root@xxx:/opt# python3 google_translate_util.py 
Traceback (most recent call last):
  File "google_translate_util.py", line 29, in <module>
    print(translate(text, "zh"))
  File "google_translate_util.py", line 19, in translate
    return translator.translate(text, lang_tgt=lang_type)
  File "/usr/local/lib/python3.6/dist-packages/google_trans_new/google_trans_new.py", line 188, in translate
    raise e
  File "/usr/local/lib/python3.6/dist-packages/google_trans_new/google_trans_new.py", line 152, in translate
    response = json.loads(response)
  File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.6/json/decoder.py", line 342, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 3085 (char 3084)

modify

/usr/local/lib/python3.6/dist-packages/google_trans_new/google_trans_new.py` line 151

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

Test

root@xxx:/opt# python3 google_translate_util.py 
工具