Elan Ruskin wrote:
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

This looks to be the same issue as bug 2009780:

http://sourceforge.net/tracker/index.php?func=detail&aid=2009780&group_id=78018&atid=551954

It's due to the way Idle sets the locale.  This is fixed in build 212.

       Roger

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to