[python-win32] "Property '%s.%s' can not be set" on read/write attribute

Tim Johnson tojo2000 at gmail.com
Wed Jan 30 02:21:31 CET 2008


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)


On Jan 29, 2008 4:51 PM, Tim Johnson <tojo2000 at gmail.com> wrote:

> Thanks, I always forget about makepy (what a terrible name).  I'm still
> relatively new to Python.
>
>
> On Jan 29, 2008 4:39 PM, Mark Hammond <mhammond at skippinet.com.au> wrote:
>
> >  I can't see docs for that property, but if it takes optional params, it
> > might have been transformed to a SetRuleName() method.  You could try
> > adding:
> >
> >
> >
> > rule_obj. _print_details_()
> >
> >
> >
> > and see what is dumped.  Finally, if you can use makepy, the generated
> > file should make it clearer to see what is going on.
> >
> >
> >
> > Cheers,
> >
> >
> >
> > Mark
> >
> >
> >
> > *From:* python-win32-bounces at python.org [mailto:
> > python-win32-bounces at python.org] *On Behalf Of *Tim Johnson
> > *Sent:* Wednesday, 30 January 2008 11:18 AM
> > *To:* python-win32 at python.org
> > *Subject:* [python-win32] "Property '%s.%s' can not be set" on
> > read/write attribute
> >
> >
> >
> > So I'm trying to automate some tasks with SMS, and I've run into a
> > roadblock when creating new collection membership rules.  The code below is
> > a method of a Collection object.  It's a rough draft, so don't worry too
> > much about the top half unless you think it might be screwing something up.
> > My problem is that I go to create a new SMS_CollectionRuleDirect object (at
> > the bottom of the code provided) and I get the following error:
> >
> >
> >
> > >>> coll.AddMembershipRule(rule)
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> >   File "H:\p4rootw\lib\ops\sms.py", line 495, in AddMembershipRule
> >     rule_obj.RuleName = name
> >   File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
> > 550, in __setattr__
> >     raise AttributeError, "Property '%s.%s' can not be set." %
> > (self._username_, attr)
> >
> >
> >
> > If you look in the SMS 2003 SDK v3.1 or here (
> > http://www.microsoft.com/technet/prodtechnol/sms/sms2003/opsguide/ops_854m.mspx?mfr=true)
> > you can see that the property is indeed Read/Write.  Is there any way to
> > override this or some workaround that I can use to fix this?  I'm about
> > ready to start hopping up and down in my office chair like an angry
> > chimpanzee.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > # This is a method of an sms.Collection object.
> >
> > #
> >
> > # self.parent.wmi_connection is an object created via wmi.WMI() with the
> >
> >
> > #   namespace set to \\server\root\sms\site_S01,
> >
> > #   and I can retrieve information fine, as well as add/edit Collection,
> >
> >
> > #   advertisement, and other objects just fine.
> >
> > #
> >
> > # self.parent.db_connection is an object created via odbc.odbc(),
> > connected to the SMS database
> >
> >
> >
> >   def AddMembershipRule(self, rule):
> >     """Adds a membership rule using an sms.MemberShipRule object.
> >
> >     Note: this method only supports adding System Resources through
> > direct
> >           membership, not User or Group Resources.
> >
> >     Args:
> >       rule: an sms.CollectionMembershipRule object
> >
> >     Raises:
> >       TypeError: if rule is not an sms.CollectionMembershipRule object
> >       SmsUnsupportedResourceType: if a direct membership rule for a
> > non-system
> >         resource type is passed
> >
> >     Returns:
> >       True on Success
> >       None on Failure
> >
> >     TODO: Remove object type limitation for direct membership rules
> >     """
> >     if not isinstance(rule, CollectionMembershipRule):
> >       raise TypeError
> >
> >     self.parent.ConnectWmi()
> >     self.parent.ConnectDb()
> >     conn = self.parent.wmi_connection
> >
> >     if rule.type == 'direct':
> >       if rule.resource_type != 5:
> >         raise SmsUnsupportedResourceType
> >
> >       cursor = self.parent.db_connection.cursor()
> >       cursor.execute('SELECT Netbios_Name0, Name0 from v_R_System '
> >                      'WHERE ResourceID = %s' % rule.resource_id)
> >       names = cursor.fetchall()
> >       name = None
> >
> >       if names[0]:
> >         name = names[0]
> >       else:
> >         name = names[1]
> >
> >
> >
> >       # This is the problem section
> >
> >       rule_obj = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_()
> >       rule_obj.ResourceClassName = 'SMS_R_System'
> >       rule_obj.RuleName = name
> >       rule_obj.ResourceID = rule.resource_id
> >       coll_obj = conn.Get('SMS_Collection.CollectionID="%s"'
> >                           % self.collection_id)
> >       coll_obj.AddMembershipRule(rule_obj)
> >
> >
> >
> >
> >
> > --
> > _____________________
> > Ceci n'est pas un email.
> >
>
>
>
> --
> _____________________
> Ceci n'est pas un email.
>



-- 
_____________________
Ceci n'est pas un email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20080129/6af7cc56/attachment-0001.htm 


More information about the python-win32 mailing list