I finally switched to using the Unicode builds to make my app behave consistently on all platforms (I thought). I’d been using the Unicode version on Windows for a while because that was available pre-compiled, and hadn’t noticed any problems, but now that I’ve switched on Mac I’m suddenly getting errors like this when I try to add to a TextCtrl displaying log output from a command-line process:
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0x81 in position 128: ordinal not in range(128)
I get the same thing when I try decoding with utf8 (or ascii). I’m mystified why this is suddenly happening, as I never had any problems like this when everything was using ‘str’ instead. As far as I know there is nothing special in the text I’m handling - it is simply console output (as str objects), and I’m using whatever the standard settings on a Mac bought in the US are. Is there a foolproof way to make this work, or am I misunderstanding how the unicode build works?
thanks,
Nat
(PS. I already saw http://wiki.wxpython.org/UnicodeBuild; this still doesn’t answer my question, because I don’t know what specific codec to use, only that utf8 and ascii don’t work.)
Nat Echols wrote:
I finally switched to using the Unicode builds to make my app behave
consistently on all platforms (I thought). I'd been using the Unicode
version on Windows for a while because that was available
pre-compiled, and hadn't noticed any problems, but now that I've
switched on Mac I'm suddenly getting errors like this when I try to
add to a TextCtrl displaying log output from a command-line process:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x81 in position
128: ordinal not in range(128)
I get the same thing when I try decoding with utf8 (or ascii). I'm
mystified why this is suddenly happening, as I never had any problems
like this when everything was using 'str' instead. As far as I know
there is nothing special in the text I'm handling - it is simply
console output (as str objects), and I'm using whatever the standard
settings on a Mac bought in the US are.
I guess you will need to dump that output in hex and figure out where
the 0x81 comes from. The Mac typically uses UTF-8, but 0x81 is not a
valid character in UTF-8.
Is there a foolproof way to make this work, or am I misunderstanding
how the unicode build works?
The only "foolproof" way is to understand exactly what you're getting.
The character '0x81' doesn't mean anything without knowing what
character encoding was being used.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.