PyPi release is outdated which causes JSON decode error on Google Colab
See original GitHub issueGoogle 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:
- Created 2 years ago
- Reactions:3
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is still a thing and its an annoying thing
Ok half of the issues are now just people asking for a new PyPi release.