如何使用python suds为工厂创建的simpletype对象赋值?
发布时间:2020-12-20 13:30:49 所属栏目:Python 来源:网络整理
导读:我正在使用 python suds使用Cisco AXL库.我试图调用一个函数,我需要使用一个simpleType,它是一个带有名称限制的字符串的特殊实例. 在成功解析WSDL之后,我使用工厂创建了我的对象: uuid = client.factory.create('ns0:XUUID') 这是在WSDL附带的XSD中如下定义
我正在使用
python suds使用Cisco AXL库.我试图调用一个函数,我需要使用一个simpleType,它是一个带有名称限制的字符串的特殊实例.
在成功解析WSDL之后,我使用工厂创建了我的对象: uuid = client.factory.create('ns0:XUUID') 这是在WSDL附带的XSD中如下定义的以下XUUID对象的实例: <xsd:simpleType name="XUUID"> <xsd:restriction base="xsd:string"> <xsd:pattern value="{........-....-....-....-............}"/> </xsd:restriction> </xsd:simpleType> 我想现在设置我的uuid对象的值,我尝试了以下所有内容但没有成功: uuid.setText('{900AAAAC-E454-0B7E-07FD-FD67D48FF50E}') uuid.set('{900AAAAC-E454-0B7E-07FD-FD67D48FF50E}') 很明显,如果这是一个带有子元素的complexType,我可以设置它们,例如在suds文档中的Person.name.我无法弄清楚如何设置此对象的值. 对象的打印目录(uuid)暗示我可能以错误的方式进行此操作. ['__contains__','__delattr__','__doc__','__getitem__','__init__','__iter__','__keylist__','__len__','__metadata__','__module__','__printer__','__repr__','__setattr__','__setitem__','__str__','__unicode__'] 如果我遗漏了一些基本的或者使用suds完全错误的话,我将在下面解释一下上下文. 我正在尝试从WSDL调用以下函数: <operation name="getDevicePool"> <input message="s0:getDevicePoolIn"/> <output message="s0:getDevicePoolOut"/> </operation> <message name="getDevicePoolIn"> <part element="xsd1:getDevicePool" name="axlParams"/> </message> 它反过来引用以下XSD元素: <xsd:element name='getDevicePool' type='axlapi:GetDevicePoolReq'></xsd:element> <xsd:complexType name='GetDevicePoolReq'> <xsd:sequence> <xsd:choice> <xsd:element name='name' type='axlapi:String100'></xsd:element> <xsd:element name='uuid' type='axlapi:XUUID'></xsd:element></xsd:choice> <xsd:element name='returnedTags' type='axlapi:RDevicePool' minOccurs='0'></xsd:element></xsd:sequence><xsd:attribute use='optional' name='sequence' type='xsd:unsignedLong'></xsd:attribute></xsd:complexType> 我尝试了一种与WSDL中的另一个函数兼容的方法: searchCriteria = { 'callManagerGroupName':'Default' } devicePools = client.service.listDevicePool(searchCriteria) 但它在这里不起作用,我相信这是因为我需要我的UUID搜索字符串是一个XUUID类型. 解决方法
工厂创建的对象通过对象属性分配值.作为我自己的代码的一个例子:
>>> api = gcs.provider.get_api() >>> client = api.get_client(api.API_DOMAIN) >>> ident = client.factory.create('ns0:Identification') >>> ident (Identification){ token = None user = None userPasswd = None oper = None operPasswd = None language = None } >>> ident.user = 'Jeremy' >>> ident (Identification){ token = None user = "Jeremy" userPasswd = None oper = None operPasswd = None language = None } >>> setattr(ident,'user','Lewis') >>> ident (Identification){ token = None user = "Lewis" userPasswd = None oper = None operPasswd = None language = None } 您应该能够打印uuid对象以查看该属性的调用,然后只需指定该值. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |