使用包含任何AnyObject类型的zeep创建请求

时间:2018-08-08 22:27:09

标签: python soap request zeep

这基本上是这里的相同问题:

creating any object with python zeep

我正在研究一个包含SOAP API调用的Python脚本。这些通常都可以正常工作,但是我有一个问题。我有SOAPUI示例,它看起来像这样:

有效的肥皂ui

<!-- language: lang-xml -->
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="Urn:ApiService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:getAllOperationalDevices soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <in0 xsi:type="api:ResourceIdentityInfo" xmlns:api="http://api.common.configmgr.powerup.com">
          <resourceKey xsi:type="soapenc:string">0a053ebeddf9e53f53e125d364010000</resourceKey>
         <resourceName xsi:type="soapenc:string">Customer1</resourceName>
         <resourceType xsi:type="soapenc:string">NETWORK</resourceType>
         </in0>
          <in1 xsi:type="fil:FilterInfo" xmlns:fil="http://filter.api.common.configmgr.powerup.com">
               <filterComponents>
                    <FilterExpressionInfo xsi:type="ns:FilterExpressionInfo" xmlns:ns="http://filter.api.common.configmgr.powerup.com">
                        <attributeName>managementIpAddress</attributeName>
                        <value xsi:type="xsd:string">10.10.10.10</value> 
                        <operator>==</operator>
                    </FilterExpressionInfo>
                </filterComponents>
          </in1>
      </urn:getAllOperationalDevices>
   </soapenv:Body>
</soapenv:Envelope>

我在WSDL中看到过滤器值是     AnyType:

我在zeep文档中看到对AnyType进行特殊处理,并在下面的代码中复制了示例:

AnyType的zeep文档示例

client = Client('http://my-entrprisy-endpoint.com')
value = xsd.AnyObject(xsd.String(), 'foobar')
client.service.submit_something(user_id=1, my_string=value)

我在zeep中创建此请求的尝试如下:

我的返回错误的python

print("API: getAllOperationalDevices")
in0 = {'resourceKey':nkey,'resourceName':nname,'resourceType':ntype}
value = xsd.AnyObject(xsd.String(),dmgmtip)
filter = {'attributeName':'managementIpAddress','value':value,'operator':'=='}
feInfo = {'FilterExpressionInfo' : [filter]}
filComp = {'filterComponents' : feInfo}
result = client.service.getAllOperationalDevices(in0,filComp)

我认为这应该很接近了,但出现以下错误:

我的python错误

File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/zeep/xsd/elements/any.py", line 181, in validate
raise exceptions.ValidationError("Missing element for Any")

我尝试使用zeep的client.service.get_element和client.service.get_type的尝试失败,因为无法识别名称空间,似乎应该是“ urn:getAllOperationalDevices”,但显然不是。

如果有人可以按正确的方向推动我,我将不胜感激!

0 个答案:

没有答案
相关问题