googletrans python api - No JSON object could be decoded error -
in file there consisting of sentences having both hindi , english words . , trying convert the words in hindi english , making every words english. conversion using googletrans api of python.here sentences of file:
शराबी politicians have work not necessary . let me tell child percentage more hindus in india. - john कॉलिन्स don't want they're not ध्यान %{appname} wants send लेकिन need signed in in chrome. important size user authentication required vpn connection '%s'... सतल width reset 2.जीवाणुओं होना। होना। suhasi goradia dhami last part of these vedas called कहलाता युगधर्म governor of kashmir arrested enterprise , voice given voice . condition of people before you. in fact, not गाजा गाजा गाजा has start मिस्र when there 2 men , , , past , , future becomes sense of mind , , , , , in future , written in past . , wrong in recent decades there lot of electricity , differences in दशकों of ग्लोबल दशकों , extreme effect पड़ने may want support special school , special school , or free school , or free school . display mapping please ensure use correct form . there 2 people here . ” vivacity manu bhandari category : religious book period ओतप्रोत भक्ति “ ' s right . ” there justice e-mail applications added same day . allow login if write permissions on user's home directory डाउनलोड(&d) great britain @ 2008 summer olympics first 2 tried मुकदमा case of 2 मुखबिरों . people of higher number , people of higher row of higher , higher class has told new education of new education has laid down . in recent nepal government service present government service , modern चिकीत्सा 5 years old, can dissolved before under sessions court , court had right decide rs 200 . displacements , economic damage , economic damage due evidence of growing population of population of population , though जनसँख्या area may less due जनसँख्या of शीतोष्ण . लाडड़ी popular woman . in water of water , 0.001 सल्फाइड of hydrogen सल्फाइड in water भी . islam second religion of islam on basis of अनुयाइयों धर्म second religion of दुनिया changed result of genetic disease of 1 , genetic disease of these diseases in same disease rules of नियम of संतानों . felt long dream , , hands लगा hands . later , financial institutions फिलहाल -lrb- last 50 per cent - rrb- , common people of common people . गवाक्षन बैठ aurangzeb
and here code:
#!/usr/bin/python # -*- coding: utf-8 -*- import googletrans import codecs import supportedlang gs = googletrans.translator() fr = codecs.open("11th.txt","r").readlines() fw = open("translatedopennmt.txt","w") count = 1 in fr : print count count = count+1 = i.strip() lst = i.split(' ') k = list() string = str() j in lst: lang_lst = gs.detect(j) lng = lang_lst.lang if lng == 'hi': word_lst = gs.translate(j) word = str(word_lst.text) else: word = str(j) k.append(word) string = ''.join(str(x)+' ' x in k) fw.write(string+'\n')
and when encounter following line :
later , financial institutions फिलहाल -lrb- last 50 per cent -rrb- , common people of common people .
it displays following error:
traceback (most recent call last): file "cgtrans.py", line 23, in <module> lang_lst = gs.detect(j) file "/usr/local/lib/python2.7/dist- packages/googletrans/client.py", line 207, in detect data = self._translate(text, dest='en', src='auto') file "/usr/local/lib/python2.7/dist- packages/googletrans/client.py", line 63, in _translate data = utils.format_json(r.text) file "/usr/local/lib/python2.7/dist-packages/googletrans/utils.py", line 51, in format_json converted = json.loads(text) file "/usr/lib/python2.7/json/__init__.py", line 339, in loads return _default_decoder.decode(s) file "/usr/lib/python2.7/json/decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) file "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode raise valueerror("no json object decoded") valueerror: no json object decoded
so how resolve issue?
probably might converting returned -detected(lang=hmn, confidence=0.17513999)
string json format giving errors. avoid doing have checked working fine.
simply write-
st = googletrans.translator().detect('-lrb-') print( st.lang)
output- u'hmn'
, giving no errors.
Comments
Post a Comment