I have an xmpp bot written in python. One of its plugins is able to execute OS commands and send output to the user. As far as I know, the output should be unicode-like for sending via xmpp protocol. So I tried to handle it like this:
output = os.popen(cmd).read()
if not isinstance(output, unicode):
output = unicode(output,'utf-8','ignore')
bot.send(xmpp.Message(mess.getFrom(),output))
But when Russian characters appear on the output, they are poorly converted.
sys.getdefaultencoding()
says the default command line encoding is 'ascii', but when I try to do
output.decode('ascii')
in python console i get
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position 1:
ordinal not in range(128)
OS: Win XP, Python 2.5.4 PS: Sorry for my English: (
source
share