Stumbled upon some seemingly random character mangling in eclipse-pydev console: specific characters are read from stdout as '\xd0?' (first byte correct, second "?")
Is there some solution to this?
(PyDEV 1.4.6, Python 2.6, console encoding - inherited UTF-8, Eclipse 3.5, WinXP with UK locale)
Code:
import sys
if __name__ == "__main__":
for l in sys.stdin:
print 'Byte: ', repr(l)
try:
u = repr(unicode(l))
print 'Unicode:', u
except Exception, e:
print 'Fail: ', e
Input:
йцукенгшщзхъ
фывапролджэ
ячсмитьбю
ЙЦУКЕНГШЩЗХЪ
ФЫВАПРОЛДЖЭ
ЯЧСМИТЬБЮ
and output:
Byte: '\xd0\xb9\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd\xd0\xb3\xd1\x88\xd1\x89\xd0\xb7\xd1\x85\xd1\x8a\r\n'
Unicode: u'\u0439\u0446\u0443\u043a\u0435\u043d\u0433\u0448\u0449\u0437\u0445\u044a\r\n'
Byte: '\xd1\x84\xd1\x8b\xd0\xb2\xd0\xb0\xd0\xbf\xd1\x80\xd0\xbe\xd0\xbb\xd0\xb4\xd0\xb6\xd1?\r\n'
Fail: 'utf8' codec can't decode bytes in position 20-21: invalid data
Byte: '\xd1?\xd1\x87\xd1?\xd0\xbc\xd0\xb8\xd1\x82\xd1\x8c\xd0\xb1\xd1\x8e\r\n'
Fail: 'utf8' codec can't decode bytes in position 0-1: invalid data
Byte: '\xd0\x99\xd0\xa6\xd0\xa3\xd0\x9a\xd0\x95\xd0?\xd0\x93\xd0\xa8\xd0\xa9\xd0\x97\xd0\xa5\xd0\xaa\r\n'
Fail: 'utf8' codec can't decode bytes in position 10-11: invalid data
Byte: '\xd0\xa4\xd0\xab\xd0\x92\xd0?\xd0\x9f\xd0\xa0\xd0\x9e\xd0\x9b\xd0\x94\xd0\x96\xd0\xad\r\n'
Fail: 'utf8' codec can't decode bytes in position 6-7: invalid data
Byte: '\xd0\xaf\xd0\xa7\xd0\xa1\xd0\x9c\xd0\x98\xd0\xa2\xd0\xac\xd0\x91\xd0\xae\r\n'
Unicode: u'\u042f\u0427\u0421\u041c\u0418\u0422\u042c\u0411\u042e\r\n'