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

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

Open
hugocool opened this issue Jul 28, 2021 · 7 comments
Open

Comments

@hugocool
Copy link

hugocool commented Jul 28, 2021

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

@hugocool hugocool changed the title JSON decode error JSON decode error on Google Colab Jul 28, 2021
@hugocool hugocool changed the title JSON decode error on Google Colab PyPi release is outdated which causes JSON decode error on Google Colab Jul 28, 2021
@ghost
Copy link

ghost commented Jul 29, 2021

This error came after cloning:
google_new_transError: Failed to connect. Probable cause: timeout.

@sahilkhose
Copy link

Thanks a lot!

@talpay
Copy link

talpay commented Aug 12, 2021

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

@TsunayoshiSawada
Copy link

This is still a thing and its an annoying thing

@fire17
Copy link

fire17 commented Jan 12, 2022

since they are not updating..
i cloned locally and extracted google_trans_new.py and constant.py to my project folder

changed line 8 of google_trans_new.py
from
from .constant import LANGUAGES, DEFAULT_SERVICE_URLS
to
from constant import LANGUAGES, DEFAULT_SERVICE_URLS

removed google_trans_new from requirements.txt

and so my original import from code can stay the same..
from google_trans_new import google_translator

working on heroku now :)

@aranjan-covanta
Copy link

removed google_trans_new from requirements.txt

Can you tell me where the requirements.txt file is? I am unable to locate it when I cloned the repo (it isn't in the file list).

@fire17
Copy link

fire17 commented Mar 25, 2022

removed google_trans_new from requirements.txt

Can you tell me where the requirements.txt file is? I am unable to locate it when I cloned the repo (it isn't in the file list).

requirements.txt is a file i have in my repo, heroku pip installs all of them prior to running my code
if you dont have it, it seems you're not using external python packages on heroku anyhow
therefore putting google_trans_new.py and constant.py in your project folder will let you use the local version when importing

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

6 participants