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

JSONDecodeError: Expecting value #22

Closed
Leena266 opened this issue Apr 14, 2017 · 4 comments
Closed

JSONDecodeError: Expecting value #22

Leena266 opened this issue Apr 14, 2017 · 4 comments

Comments

@Leena266
Copy link

Leena266 commented Apr 14, 2017

I am trying to translate multiple text documents from english to french. it worked fine then all of a sudden this error showed up.

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

Any idea how to fix it?

Here is my code:

from googletrans import Translator
import glob, os

translator = Translator()

os.chdir("documents path")
save_path = "path" 

for file in glob.glob("*.txt"):
    myfile= open(file,'r')
    completeName = os.path.join(save_path, file)
    myfile2=open(completeName, encoding='utf-16', mode='w+')
    for line in myfile:
        trans=translator.translate(line,dest="fr")
        myfile2.write(trans.text)
        myfile2.write('\r\n')
        
    myfile.close()
    myfile2.close() 

@ssut
Copy link
Owner

ssut commented Apr 14, 2017

I'm not sure where the error actually happened. Could you give me some more information such as length of the text, or http response(import logging; logging.setLevel(logging.DEBUG)).

@gromov-alar
Copy link

gromov-alar commented Jun 6, 2017

Hi, i use ipdb for geting this error text.
Response said that Request Entity too large. Got this error if text size more then 3000 characters

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

In [7]: translator.translate(text[:3500], 'en')
> /home/zaebee/.virtualenvs/ww3/lib/python3.6/site-packages/googletrans/utils.py(52)format_json()
     51     import ipdb;ipdb.set_trace()
---> 52     converted = json.loads(text)
     53     return converted

ipdb> text
'<!DOCTYPE html>\n<html lang=en>\n  <meta charset=utf-8>\n  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">\n  <title>Error 413 (Request Entity Too Large)!!1</title>\n  <style>\n    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}\n  </style>\n  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>\n  <p><b>413.</b> <ins>Thatâ\x80\x99s an error.</ins>\n  <p>Your client issued a request that was too large.\n <script>\n  (function() { var c=function(a,d,b){a=a+"=deleted"+("; path="+d);null!=b&&(a+="; domain="+b);document.cookie=a+"; expires=Thu, 01 Jan 1970 00:00:00 GMT"};var g=function(a){var d=e,b=location.hostname;c(d,a,null);c(d,a,b);for(var f=0;;){f=b.indexOf(".",f+1);if(0>f)break;c(d,a,b.substring(f+1))}};var h;if(4E3<unescape(encodeURI(document.cookie)).length){for(var k=document.cookie.split(";"),l=[],m=0;m<k.length;m++){var n=k[m].match(/^\\s*([^=]+)/);n&&l.push(n[1])}for(var p=0;p<l.length;p++){var e=l[p];g("/");for(var q=location.pathname,r=0;;){r=q.indexOf("/",r+1);if(0>r)break;var t=q.substring(0,r);g(t);g(t+"/")}"/"!=q.charAt(q.length-1)&&(g(q),g(q+"/"))}h=!0}else h=!1;\nh&&setTimeout(function(){if(history.replaceState){var a=location.href;history.replaceState(null,"","/");location.replace(a)}},1E3); })();\n</script>\n <ins>Thatâ\x80\x99s all we know.</ins>\n'

@zemicolumn
Copy link

zemicolumn commented Aug 25, 2017

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

trans = Translator()
trans.translate(',,')

or

trans.translate('asdsa\x44\x44asdsa')

@ssut
Copy link
Owner

ssut commented Sep 9, 2017

@gromov-alar so it looks like it's expected behavior that the text size should be less than 15K, as I mentioned in the README.

@ssut ssut added this to the Refactor googletrans milestone Oct 1, 2017
@ssut ssut closed this as completed Oct 1, 2017
@ssut ssut removed this from the Refactor googletrans milestone Oct 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants