WMI - invalid syntax error?

Tim Golden tim.golden at viacom-outdoor.co.uk
Fri Dec 30 10:08:21 EST 2005


[py]

> import wmi
> # the ip of my own local desktop
> machine = "1.2.3.4"
> try:
>     w = wmi.WMI(machine)  # also tried, wmi.WMI(computer=machine)
> except Exception, e:
>     print "ERROR:", e
.
.
> c:>python
> >>> from MyScript import *
> >>> ERROR: -0x7ffbfe1c - Invalid syntax
.
.
> here's the trace...
>
>  File "MyScript.py", line 10,
>    wmiObj = wmi.WMI(machine)
>  File "wmi.py", line 519, in __init__
>    handle_com_error (error_info)
>  File "wmi.py", line 131, in handle_com_error
>    raise x_wmi, "\n".join (exception_string)
> x_wmi: -0x7ffbfe1c - Invalid syntax
.
.
> one more note, I am using WMI v0.6 ....however, I also tried it with
> the latest version 1.0 rc2.

OK, so if I understand you: at the interpreter you can do this:

<interpreter>
import wmi
w = wmi.WMI ("1.2.3.4")
# no problem
</interpreter>

but if you put it into a file and then import * from
that file, it fails with a wmi exception:

<blah.py>
import wmi
w = wmi.WMI ("1.2.3.4")
</blah.py>

<interpreter>
from blah import *
## some kind of x_wmi exception happens here
</interpreter>

And this happens on wmi 0.6 and 1.0rc2.

Is this correct? 

It's just that you've got several things which could
to be blurring the issue - the fact that you're using 
an explicit IP address rather than passing no params, 
which will then use the local machine automatically; 
you've added an exception handler which doesn't do much; 
your traceback in the second email doesn't (quite) match 
the  MyScript in the first. It's not that these are wrong - 
I'm just trying to eliminate non-essentials to get to the 
core of the thing.

In short, what I wrote above works for me on 0.6 and 1.0rc2.
A syntax error usually means that the moniker's got problems -
that's the string which the wmi module builds up on your
behalf to get something to pass to MS COM.

Could you just post (or send by private email if you prefer)
the exact script you're running? If you want to send it
privately, please us mail <at> timgolden.me.uk.

Thanks
TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-list mailing list