Python - Android logcat output of stdout to textview then save to .txt file error -
i have following python code, uses android logcat via stdout pull logs off phone wxpython text field. login app, username jack , password jack@123$ logcat output stops error, seems not @ or $ symbols:
return codecs.charmap_decode(input,errors,decoding_table) unicodedecodeerror: 'charmap' codec can't decode byte 0x9d in position 76: character maps <undefined>
or when try getvalue() of text control save .txt file open writing:
unicodeencodeerror: 'ascii' codec can't encode characters in position 204447-204449: ordinal not in range(128)
the code logcat function follows
def logcat(self): params = [toolsdir + "\\adb.exe", "logcat"] p = popen(params, stdout=subprocess.pipe, bufsize=1) line in p.stdout: #line = line.decode('latin-1') self.progressbox.appendtext(line) def savelog(self,e): f = open(outdir + '\\' + pkgname + '\\' + pkgname + '_logcat.txt', 'w') f.write(self.progressbox.getvalue()) f.close()
what correct way of implementing decoding these symbols using stdout. thanks
edit: answer follows, had decode('utf-8') stdout textbox, encode('utf-8') when writing file.
line in p.stdout: self.progressbox.appendtext(line.decode('utf-8')) f.write(self.progressbox.getvalue().encode('utf-8'))
Comments
Post a Comment