python - 如何使用 python suds 为工厂创建的简单类型对象赋值?

标签 python suds

我正在使用 python suds 处理 Cisco AXL 库。我正在尝试调用一个需要使用 simpleType 的函数,它是具有名称限制的特殊字符串实例。

我在成功解析 WSDL 后使用工厂创建我的对象:

 uuid = client.factory.create('ns0:XUUID')

这是以下 XUUID 对象的一个​​实例,在 WSDL 随附的 XSD 中定义如下:

 <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}')

很明显,如果这是一个带有子元素的复杂类型,我将能够设置它们,例如Person.name 与 suds 文档中的一样。我不知道如何设置这个对象的值。

对象的打印目录 (uuid) 表明我可能以错误的方式处理此问题。

 ['__contains__', '__delattr__', '__doc__', '__getitem__', '__init__', '__iter__', '__keylist__', '__len__', '__metadata__', '__module__', '__printer__', '__repr__', '__setattr__', '__setitem__', '__str__', '__unicode__']

如果我遗漏了一些基本的东西或者完全错误地使用了肥皂水,我将在下面解释更多的上下文。

我正在尝试从 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 对象以查看调用的属性,然后简单地分配值。

关于python - 如何使用 python suds 为工厂创建的简单类型对象赋值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13103023/

相关文章:

python - 使用 python 使用准确的标签将时间范围扩展为更小增量的更多步骤

python - 在 Python2 和 Python3 中写入不同的十六进制值

python - spyne SOAP 服务器的 Hello world 示例

Python suds - 服务中未定义方法

python suds UsernameToken

python - 重复提取文本文件中两个分隔符之间的一行,Python

python - 在 tensorflow 中访问 python 列表和张量的优雅方式

python - cx_freeze 只读站点包的解决方法

python - 未找到类型 : '(schema, http ://www. w3.org/2001/XMLSchema,)

python - 如何使用 suds (Python) 对 HTTP 代理进行身份验证?