[python-win32] UnicodeDecodeError in WMI interface (Py 2.5; US English XP)

Elan Ruskin eruskin at valvesoftware.com
Wed Aug 20 02:17:51 CEST 2008


Hello, I've run into some trouble with the pywin32 WMI interface that
seems to be due to unicode translation.
 
I'm trying to read system environment variables using Microsoft's own
example here:
http://www.microsoft.com/technet/scriptcenter/scripts/python/desktop/exp
lorer/dmexpy03.mspx?mfr=true
 
However, the example fails with a UnicodeDecodeError exception as soon
as I try to access an attribute on the WMIService. The problem appears
to be in the __getattr__() on <COMObject WbemScripting.SWbemLocator> and
not inside the WMI service itself. For example, the following code
crashes:
 
>>> import win32com.client
>>> objWMIService =
win32com.client.Dispatch("WbemScripting.SWbemLocator")
>>> objWMIService.ConnectServer
Traceback (most recent call last):
  File "<pyshell#23>", line 1, in <module>
    dir(objWMIService.ConnectServer)
  File
"U:\dev\l4dbranch\game\sdktools\python\2.5\lib\site-packages\win32com\cl
ient\dynamic.py", line 467, in __getattr__
    (...)
  File
"U:\dev\l4dbranch\game\sdktools\python\2.5\lib\site-packages\win32com\cl
ient\build.py", line 542, in <lambda>
    return filter( lambda char: char in valid_identifier_chars,
className)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in position 52:
ordinal not in range(128)


Googling around for this problem revealed another thread (
http://tinyurl.com/597pfp ) on the same issue, but no resolution or
workaround. 

Do I need to put my Python in some sort of Unicode Mode or something? I
can't seem to find any other documentation of what's going on here.

I'm running plain US English XP, no international features installed.
I'm using the stable Python 2.5 from python.org. 

Alternatively, does anyone know another convenient way I can read and
set persistent SYSTEM and USER environment variables through Python?

Thanks,
Elan


More information about the python-win32 mailing list