question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PyPi release is outdated which causes JSON decode error on Google Colab

See original GitHub issue

Google trans new does not work in Google Colab when installed through pypi

!pip install google_trans_new

input:

from google_trans_new import google_translator  
  
translator = google_translator()  
translate_text = translator.translate('สวัสดีจีน',lang_tgt='en')  
print(translate_text)

error:

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
<ipython-input-7-a6eb592f82a8> in <module>()
      2 
      3 translator = google_translator()
----> 4 translate_text = translator.translate('สวัสดีจีน',lang_tgt='en')
      5 print(translate_text)
      6 

3 frames
/usr/local/lib/python3.7/dist-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:

/usr/local/lib/python3.7/dist-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])

/usr/lib/python3.7/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

/usr/lib/python3.7/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 339 (char 338)

I think the package is not updated on pypi, the latest release dates from dec 2020, while your latest commit is from 17 days ago.

This can be temporarily solved by doing

!git clone https://github.com/lushan88a/google_trans_new.git
from google_trans_new.google_trans_new import google_translator  
  
translator = google_translator(url_suffix='nl',timeout=9)  
translate_text = translator.translate('สวัสดีจีน',lang_tgt='en')  
print(translate_text)
>>> Hello Chinese

A new pypi release might fix all the issues

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

1reaction
TsunayoshiSawadacommented, Sep 18, 2021

This is still a thing and its an annoying thing

1reaction
talpaycommented, Aug 12, 2021

Ok half of the issues are now just people asking for a new PyPi release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSONDecode error while using Google colab - Stack Overflow
I am trying to use google colab for a project of mine but been stuck at this error since a long time. Any...
Read more >
google-trans-new 1.1.9 - PythonFix.com
A free and unlimited python tools for google translate api. ... PyPi release is outdated which causes JSON decode error on Google Colab...
Read more >
Python quickstart | Google Docs
Create a Python command-line application that makes requests to the Google ... Save the downloaded JSON file as credentials.json , and move the...
Read more >
Fiona - PyPI
Fiona can read and write real-world data using multi-layered GIS formats and zipped virtual file ... Records are mappings modeled on the GeoJSON...
Read more >
Python import: Advanced Techniques and Tips
Even though you're importing only csv , that module is importing re behind the scenes, so an error is raised. Example: Automatically Install...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found