Mike Miller
2013-10-02 03:30:22 UTC
Hi,
I've been searching for information on character encoding and fabric but coming
up empty. I've got a command printing an occasional Unicode char and so when
using the result object I get a UnicodeDecodeError:
output = run('unicode_printer')
'returned: ' + output # kaboom
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0:
ordinal not in range(128)
What should I do about this? I could hard-code it to decode with utf8, but
can't guarantee it will be utf8. I can imagine running a command earlier to get
the encoding and then decoding it. For example:
encoding = run("python2 -c 'import locale; " +
"print locale.getdefaultlocale()[1]'")
output = run('unicode_printer')
'returned: ' + output.decode(encoding)
Wondering if there was a parameter or easier way that I'm missing.
Thanks,
I've been searching for information on character encoding and fabric but coming
up empty. I've got a command printing an occasional Unicode char and so when
using the result object I get a UnicodeDecodeError:
output = run('unicode_printer')
'returned: ' + output # kaboom
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0:
ordinal not in range(128)
What should I do about this? I could hard-code it to decode with utf8, but
can't guarantee it will be utf8. I can imagine running a command earlier to get
the encoding and then decoding it. For example:
encoding = run("python2 -c 'import locale; " +
"print locale.getdefaultlocale()[1]'")
output = run('unicode_printer')
'returned: ' + output.decode(encoding)
Wondering if there was a parameter or easier way that I'm missing.
Thanks,