[python-win32] com_error Unicode problems
niki
niki at vintech.bg
Wed Jul 23 09:32:52 CEST 2008
Tim Golden wrote:
> There's a thread over on c.l.py which concerns the error messages
> returned from the WMI module, which
> uses win32com.client and all its works and promises...
>
> http://mail.python.org/pipermail/python-list/2008-July/499172.html
>
> The OP is running on a Simple Chinese edition of Windows XP,
> and the error message, naturally, returns Simple Chinese
> characters. But... it's apparent that the com_error info
> structure returns not Unicode but byte stream. I *think*
> I can decode into Unicode by using the sys.stdout.encoding,
> but even if I'm right that's a fragile solution: running
> under the SciTE editor, eg, sys.stdout.encoding is None.
>
> So, a couple of questions:
>
> 1) Is there some API which will tell me: non-Unicode error
> messages can be converted to Unicode *thus*. I've looked
> around, but there's nothing too obvious.
>
> 2) How onerous would it be to change PyCom_BuildPyException
> to call FormatMessageW and to return true Unicode objects?
> Non-trivial, I imagine, since that function's called everywhere,
> but maybe now's the time...?
>
> [... three questions; nobody expects ...]
>
> 3) Is there something more obvious which I've missed?
Yes use 'mbcs' codec :)
HTH
Niki Spahiev
More information about the python-win32
mailing list