About wmi

P

patrol

patrol said:
Assuming that the error comes back in the sys.stdout encoding, the following version *should* work ok. I still haven't got a non-English set up to test it on, but it certainly does return a Unicode error message.
http://timgolden.me.uk/wmi-project/wmi.py
The usual test case, if you wouldn't mind:
<code>
import wmi
wmi.WMI ("non-existent computer")
</code>
should give a (language-specific) error message, not an UnicodeDecodeError
TJG --------------------------------------------------------------------------------------
import wmi
wmi.WMI('non-existent computer')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python25\lib\wmi.py", line 1199, in connect
handle_com_error (error_info)
File "C:\Python25\lib\wmi.py", line 184, in handle_com_error
exception_string = [u"%s - %s" % (hex (hresult_code),
hresult_name)]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb7 in position
4: ordinal
not in range(128)

Can you confirm that that last bit of
code was run with the version of wmi.py
currently at:

http://timgolden.me.uk/wmi-project/wmi.py

That version should already be decoding the
string correctly.

TJG ----------------------------------------------------------------------------------------

Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
wmi.WMI('non-existent computer')
File "C:\Python25\lib\wmi.py", line 1199, in connect
handle_com_error (error_info)
File "C:\Python25\lib\wmi.py", line 189, in handle_com_error
raise x_wmi, u"\n".join (exception_string)
x_wmi: <unprintable x_wmi object>
------------------------------------------------------------------------------------------
# -*- coding:utf-8 -*-
import wmi
from time import sleep

c = wmi.WMI ()
process_watcher = c.Win32_Process.watch_for("creation")
while True:
new_process = process_watcher()
if new_process.Caption == 'notepad.exe':
print "start killing.."
sleep(5)
result = new_process.Terminate()
print "killed"
When I kill the notepad.exe manually,it also results in errors.
Traceback (most recent call last):
File "C:\Documents and Settings\patrol\×ÀÃæ\test.py", line 12, in
<module>
result = new_process.Terminate()
File "C:\Python25\lib\wmi.py", line 396, in __call__
handle_com_error (error_info)
File "C:\Python25\lib\wmi.py", line 188, in handle_com_error
exception_string.append (u" %s - %s" % (hex (scode),
(error_description or
u"").decode (sys.stdout.encoding).strip ()))
UnicodeEncodeError: 'ascii' codec can't encode characters in position
0-2: ordin
al not in range(128)
 
P

patrol

I will try to modify the wmi.py ,however I'm a novice.It will take a
long time. You can give it up temporarily. If you don't mind ,can you
tell me where needs modifying and how? Just unicode? Or Other?
 
T

Tim Golden

patrol said:
I will try to modify the wmi.py ,however I'm a novice.It will take a
long time. You can give it up temporarily. If you don't mind ,can you
tell me where needs modifying and how? Just unicode? Or Other?

OK. Thanks for your patience on this one, Patrol. What I propose
to do is to dig into the pywin32 sources to determine what's going
on when the error messages are fetched. Then I'll be better placed
to decide what to do when they come out. On the surface, the current
module should be handling things correctly; but I've obviously missed
an encode/decode somewhere.

If I can think of an (even hackish) workaround for you in the meantime,
I'll let you know. Until then...

TJG
 
P

patrol

OK. Thanks for your patience on this one, Patrol. What I propose
to do is to dig into the pywin32 sources to determine what's going
on when the error messages are fetched. Then I'll be better placed
to decide what to do when they come out. On the surface, the current
module should be handling things correctly; but I've obviously missed
an encode/decode somewhere.

If I can think of an (even hackish) workaround for you in the meantime,
I'll let you know. Until then...

TJG

Thanks for Tim's help.

Patrol
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top