[python-win32] "Property '%s.%s' can not be set" on read/write attribute
Tim Golden
mail at timgolden.me.uk
Wed Jan 30 10:14:57 CET 2008
Tim Johnson wrote:
> Hmm, I'm getting a different error now. Could it be having trouble passing
> one wmi object as a parameter to the method of another?
>
> import wmi
> site = 'MV1'
> wmi_server = 'mtv-sql-2'
> resource = 23012
> wmi_namespace = 'root\\sms\\site_%s' % site
> conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace)
> coll = conn.Get('SMS_Collection.CollectionID="MV100362"')
> rule = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_()
> rule.ResourceID = resource
> rule.RuleName = 'ResourceID: ' +str(resource)
> rule.ResourceClassName = 'SMS_R_System'
> coll.AddMembershipRule(rule)
>
> Gives me :
>
> Traceback (most recent call last):
> File "C:\Users\timjohnson\Desktop\addrule.py", line 16, in ?
> coll.AddMembershipRule(rule)
> File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 491,
> in __getattr__
> raise pythoncom.com_error, details
> pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
> 'SWbemObjectEx', 'Not found ', None, 0, -2147217406), None)
>
> But this:
>
> import wmi
> site = 'MV1'
> wmi_server = 'mtv-sql-2'
> resource = 23012
> wmi_namespace = 'root\\sms\\site_%s' % site
> conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace)
> coll = conn.SMS_Collection(CollectionID='MV100362')[0]
> rule = conn.SMS_CollectionRuleDirect.new()
> rule.ResourceID = resource
> rule.RuleName = 'ResourceID: ' +str(resource)
> rule.ResourceClassName = 'SMS_R_System'
> coll.AddMembershipRule(rule)
>
> Gives me:
>
> Traceback (most recent call last):
> File "C:\Users\timjohnson\Desktop\addrule.py", line 16, in ?
> coll.AddMembershipRule(rule)
> TypeError: __call__() takes exactly 1 argument (2 given)
Hi, Tim.
This is one of those ones where I can't easily check my suspicions
because I don't have the namespace on my box. I can probably give
a hint or two, though. And I'll almost certainly find along the
way that you're doing something no-one's asked the wmi module to
do before and which, therefore, I don't support too cleanly!
No. 1 - get the latest release:
http://timgolden.me.uk/python/downloads/wmi-1.3.2.zip
which may actually solve the first problem if it's
what I think it is, and will certainly help you with
the second. If I'm wrong -- and even if I'm right :) --
feel free to post back.
The first one *might* be a symptom of a long-standing bug
I've just squashed which over-cached the WMI methods so
that any method call after the first one was attempting
to call on the *first* object again.
The second one is the slight gotcha that -- prior to the
latest release but one -- you had to pass method params
as keyword-only. Not helped by the slightly obscure error
message which even has me scratching my head when I forget.
I've fixed that in the latest release so please run it through
and make sure for me.
Thanks
TJG
More information about the python-win32
mailing list