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

raise JSONDecodeError("Expecting value", s, err.value) from None #113

Closed
raomanohar opened this issue May 2, 2019 · 8 comments
Closed
Labels

Comments

@raomanohar
Copy link

I am getting the below error when I try to translate a Portuguese tweet to English.
"raise JSONDecodeError("Expecting value", s, err.value) from None"

I have tried to encode the string, tried to limit the string to only 3000 characters nothing works.
Please advise how can i fix this?
The issues which were raised by others and the solutions provided are not working for me

Below is my code.

from googletrans import Translator

translator = Translator()
d = 'Eu fujo de discussão na internet como o diabo foge da cruz,  leio e expresso minha opinião p mim mesmo pq todos tão afim de lacrar além de ouvir e trocar idéias'
d = d.encode('utf-8')  
d = str(d)
translations = translator.translate(d, dest='en')
print(translations.origin, '\n -> \n', translations.text)

Error

Traceback (most recent call last):
  File "C:\Users\Stramzik\Desktop\SentizAnalyzer\jsf.py", line 8, in <module>
    translations = translator.translate(d, dest='en')
  File "C:\Users\Stramzik\AppData\Local\Programs\Python\Python37\lib\site-packages\googletrans\client.py", line 172, in translate
    data = self._translate(text, dest, src)
  File "C:\Users\Stramzik\AppData\Local\Programs\Python\Python37\lib\site-packages\googletrans\client.py", line 81, in _translate
    data = utils.format_json(r.text)
  File "C:\Users\Stramzik\AppData\Local\Programs\Python\Python37\lib\site-packages\googletrans\utils.py", line 62, in format_json
    converted = legacy_format_json(original)
  File "C:\Users\Stramzik\AppData\Local\Programs\Python\Python37\lib\site-packages\googletrans\utils.py", line 54, in legacy_format_json
    converted = json.loads(text)
  File "C:\Users\Stramzik\AppData\Local\Programs\Python\Python37\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Users\Stramzik\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\Stramzik\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[Finished in 4.3s with exit code 1]
[shell_cmd: python -u "C:\Users\Stramzik\Desktop\SentizAnalyzer\jsf.py"]
[dir: C:\Users\Stramzik\Desktop\SentizAnalyzer]
[path: C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Webex\Webex\Applications;C:\Program Files\IBM\SPSS\Modeler\18.1.1\ext\bin\spss.TMWBServer\bin;C:\Program Files (x86)\Sennheiser\SoftphoneSDK\;C:\Users\Stramzik\AppData\Local\Programs\Python\Python37;C:\Users\Stramzik\AppData\Local\Programs\Python\Python37\Scripts;C:\Users\Stramzik\AppData\Roaming\nltk_data;C:\Users\Stramzik\AppData\Local\Microsoft\WindowsApps;C:\Users\Stramzik\AppData\Local\Box\Box Edit\]

@NawtJ0sh
Copy link

NawtJ0sh commented May 3, 2019

try removing the "d = d.encode('utf-8') "

@raomanohar
Copy link
Author

If I wont encode and if the tweet contains an emoji it Throws JSONDecodeError error.

@NawtJ0sh
Copy link

NawtJ0sh commented May 3, 2019

oh, is that how you have the code exactly in the file?

@raomanohar
Copy link
Author

Yes, Well Its so weird but it works for some time and it stops all of a sudden.
Right now the above code is running with no error. But when I submitted the issue yesterday it was throwing the above error.
I think the API wasblocking my IP from accessing it. Please assist me in bypass that?

@NawtJ0sh
Copy link

NawtJ0sh commented May 4, 2019

Yeah it might of ip banned you temporary.
Could try this aswell:

def translate(trans):
    try:
        trans = raw_input("Enter word/words here: ")
        translations = translator.translate([trans], dest='en')
        for translation in translations:
            print(translation.origin, ' English -> ', translation.text)
    except:
        try:
            trans_encode = trans.encode("ascii", "ignore")
            translations = translator.translate([trans_encode], dest='en')
            for translation in translations:
                print(translation.origin, ' English -> ', translation.text)
        except:
            pass

trans = ''
threading.Thread(translate(trans)).start()

@austinmm
Copy link

This is what I had to do to bypass their API call restriction... I use a VPN, specifically Nord-Vpn, so to do it the way I did you would need to be able to connect/disconnect from/to a VPN through the terminal...

    def translate_text(text, dest_language="en"):
        # Used to translate using the googletrans library
        import json
        translator = googletrans.Translator()
        try:
            translation = translator.translate(text=text, dest=dest_language)
        except json.decoder.JSONDecodeError:
            # api call restriction
            process = subprocess.Popen(["nordvpn", "d"], stdout=subprocess.PIPE)
            process.wait()
            process = subprocess.Popen(["nordvpn", "c", "canada"], stdout=subprocess.PIPE)
            process.wait()
            return Process_Data.translate_text(text=text, dest_language=dest_language)
        return translation

@rahilvora9
Copy link

This is what I had to do to bypass their API call restriction... I use a VPN, specifically Nord-Vpn, so to do it the way I did you would need to be able to connect/disconnect from/to a VPN through the terminal...

    def translate_text(text, dest_language="en"):
        # Used to translate using the googletrans library
        import json
        translator = googletrans.Translator()
        try:
            translation = translator.translate(text=text, dest=dest_language)
        except json.decoder.JSONDecodeError:
            # api call restriction
            process = subprocess.Popen(["nordvpn", "d"], stdout=subprocess.PIPE)
            process.wait()
            process = subprocess.Popen(["nordvpn", "c", "canada"], stdout=subprocess.PIPE)
            process.wait()
            return Process_Data.translate_text(text=text, dest_language=dest_language)
        return translation

I did import "subprocess" but how would "Process_Data" work? as is I tried pip install Process_Data but didn't think it worked

@stale
Copy link

stale bot commented Jun 10, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 10, 2020
@stale stale bot closed this as completed Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants