[python-win32] WMI troubles!

Alex Hall mehgcap at gmail.com
Fri Jan 15 19:39:49 CET 2010


Let's try this. Here is the stack trace when I ran my program. It ran fine, 
even calling the getLoad function once since that call is built into the 
code, not dependent on a keypress. This trace printed after I pressed win-`, 
the keypress I have assigned, through pyHook, to trigger a call to getLoad. 
If you want, you can change the call to getLoad to getFreeRam and a similar 
error occurs, pasted below this one.

Error from keypress calling getLoad():
C:\Users\Alex>python c:\prog\python\sys.py
Traceback (most recent call last):
  File "c:\python26\lib\site-packages\pyHook\HookManager.py", line 351, in 
Keybo
ardSwitch
    return func(event)
  File "c:\prog\python\sys.py", line 88, in OnKeyUpEvent
    speaker.say(str(getLoad()))
  File "c:\prog\python\sys.py", line 14, in getLoad
    for p in c.Win32_Processor():
  File "c:\python26\lib\site-packages\wmi.py", line 647, in query
    return self._namespace.query (wql, self, fields)
  File "c:\python26\lib\site-packages\wmi.py", line 835, in query
    return [ _wmi_object (obj, instance_of, fields) for obj in 
self._raw_query(w
ql) ]
  File "c:\python26\lib\site-packages\wmi.py", line 829, in _raw_query
    raise WMI_EXCEPTIONS.get (hresult, x_wmi (hresult))
wmi.x_wmi: -2147352567

Error from keypress calling getFreeRam():
C:\Users\Alex>python c:\prog\python\sys.py
Traceback (most recent call last):
  File "c:\python26\lib\site-packages\pyHook\HookManager.py", line 351, in 
Keybo
ardSwitch
    return func(event)
  File "c:\prog\python\sys.py", line 88, in OnKeyUpEvent
    speaker.say(str(getFreeRam()))
  File "c:\prog\python\sys.py", line 24, in getFreeRam
    for info in c.Win32_OperatingSystem():
  File "c:\python26\lib\site-packages\wmi.py", line 975, in __getattr__
    return getattr (self._namespace, attribute)
  File "c:\python26\lib\site-packages\win32com\client\dynamic.py", line 512, 
in
__getattr__
    raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: 
winmgmts:{impersonationLevel=impersonate,authenticationLevel=def
ault}//localhost/.Win32_OperatingSystem


Have a great day,
Alex
Email: mehgcap at gmail.com
----- Original Message ----- 
From: "Aahz" <aahz at pythoncraft.com>
To: "Alex Hall" <mehgcap at gmail.com>
Cc: <python-win32 at python.org>
Sent: Friday, January 15, 2010 13:18
Subject: Re: [python-win32] WMI troubles!


> On Fri, Jan 15, 2010, Alex Hall wrote:
>>
>> I am trying to put the stack trace into a file, since I cannot copy and
>> paste from the cmd line output. Is there a way to do this? Also, if you
>> run the file (assuming you have all the dependencies) the error happens
>> as soon as you press windows-`. You can change "speaker.say" to "print"
>> and comment out the line creating the speaker object so that you do not
>> have to install sayTools.
>
> You probably will have difficulty doing this, but yes, you can
> copy/paste command-line output using a mouse to select a screen area.
>
> Actually, I just looked in my Windows virtual machine and you can do
> alt-space, edit, select all, enter
>
> You can also use try/except and the traceback module to capture an
> exception and write it to a file.
> -- 
> Aahz (aahz at pythoncraft.com)           <*> 
> http://www.pythoncraft.com/
>
> "If you think it's expensive to hire a professional to do the job, wait
> until you hire an amateur."  --Red Adair 



More information about the python-win32 mailing list