Помогите исправить ошибку «повысить JSONDecodeError (« Ожидаемое значение », s, err.value) из None» - PullRequest
0 голосов
/ 03 мая 2019

Я получаю сообщение об ошибке ниже, когда пытаюсь перевести португальский твит на английский с помощью googletrans "повысить JSONDecodeError (" Ожидаемое значение ", s, err.value) из Нет"

Я пытался закодировать строку, пытался ограничить строку только 3000 символов, ничего не работает. Посоветуйте, пожалуйста, как мне это исправить?

Ниже мой код.

from googletrans import Translator

translator = Translator()
SampleText = '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'
SampleText = SampleText.encode('utf-8')  
SampleText = str(SampleText)
translations = translator.translate(SampleText, 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\]

...