简体   繁体   English

Python Zeep SOAP客户端模块-无法设置元素的属性

[英]Python Zeep SOAP client module - can't set attributes for an element

I'm a little bit rusted with Python but I need to set up a SOAP call with zeep client. 我对Python有点不满意,但是我需要使用zeep客户端设置SOAP调用。 I managed to successfully call a couple of methods by passing in only a dictionary object but I don't have luck setting this one part and I'm not sure if it's even possible using this technique. 我仅通过传入一个字典对象就成功地成功调用了几种方法,但是我没有设置这一部分的运气,而且我不确定使用这种技术是否有可能。

This is the part of the envelope I have trouble with: 这是我遇到麻烦的部分:

<xs:complexType name="setupParameter">
    <xs:sequence />
    <xs:attribute name="key" type="xs:string" use="required" />
    <xs:attribute name="value" type="xs:string" use="required" />
</xs:complexType>

which is embedded inside: 嵌入其中:

<xs:complexType name="transportSettings">
    <xs:sequence>
        <xs:element maxOccurs="unbounded" minOccurs="0" name="setupParameter" type="tns:setupParameter" />
    </xs:sequence>
</xs:complexType>

I tried passing this params like this: 我试图像这样传递这些参数:

'transportSettings': {
    [
        {'setupParameter': {'key': 'key1', 'value': 'val1'}},
        {'setupParameter': {'key': 'key2', 'value': 'val2'}}
    ]
 }

inside the envelope but it seems that it's not working. 信封里的东西,但似乎不起作用。 Since the SOAP method does not have great validation it does create two items of setupParameter type but they both are missing key and value values. 由于SOAP方法不会有很大的验证它确实创造的两项setupParameter类型,但他们都缺少keyvalue值。

Shed some light onto this for me, please. 请给我一些照明。

Edit1 编辑1

This is the output from SoapUI (part of the request) that I'm trying to replicate: 这是我尝试复制的SoapUI的输出(请求的一部分):

<transportSettings>
    <!--Zero or more repetitions:-->
    <setupParameter key="?" value="?"/>
</transportSettings>

Edit2 编辑2

So, I've added a plugin to zeep client (as described in their documentation) that prints out SOAP requests and responses and this is the request: 因此,我向zeep客户端添加了一个插件(如他们的文档中所述),该插件可以打印出SOAP请求和响应,这就是请求:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Body>
    <ns0:provisionService xmlns:ns0="http://ntc.nms.slm.hub.provisioning">
      <service>
        <vn>test</vn>
        <serviceClass>Satellite Internet Access - 3100 Forward</serviceClass>
        <linkType>MULTIPLE_ACCESS</linkType>
        <channelCarrier>false</channelCarrier>
        <transportSettings>
          <setupParameter key="" value=""/>
        </transportSettings>
        <multicastRequired>false</multicastRequired>
        <linkTopology>POINT_TO_POINT</linkTopology>
        <serviceGuiOptions>
          <enableBooking>true</enableBooking>
          <enableUnManagedTransmitter>false</enableUnManagedTransmitter>
          <enableCustomSetupParameters>true</enableCustomSetupParameters>
        </serviceGuiOptions>
        <qosParameters>
          <bestEffortPirFixed>0</bestEffortPirFixed>
          <bestEffortPirPct>0</bestEffortPirPct>
          <criticalData1CirFixed>0</criticalData1CirFixed>
          <criticalData1CirPct>0</criticalData1CirPct>
          <criticalData1PirFixed>0</criticalData1PirFixed>
          <criticalData1PirPct>0</criticalData1PirPct>
          <criticalData2CirFixed>0</criticalData2CirFixed>
          <criticalData2CirPct>0</criticalData2CirPct>
          <criticalData2PirFixed>0</criticalData2PirFixed>
          <criticalData2PirPct>0</criticalData2PirPct>
          <criticalData3CirFixed>0</criticalData3CirFixed>
          <criticalData3CirPct>0</criticalData3CirPct>
          <criticalData3PirFixed>0</criticalData3PirFixed>
          <criticalData3PirPct>0</criticalData3PirPct>
          <realTime1CirFixed>6000</realTime1CirFixed>
          <realTime1CirPct>0</realTime1CirPct>
          <realTime2CirFixed>0</realTime2CirFixed>
          <realTime2CirPct>0</realTime2CirPct>
          <realTime3CirFixed>0</realTime3CirFixed>
          <realTime3CirPct>80</realTime3CirPct>
        </qosParameters>
      </service>
    </ns0:provisionService>
  </soap-env:Body>
</soap-env:Envelope>

that is created from this input dictionary (by passing in like this - client.service.serviceName(inputDict) ): 从此输入字典创建的(通过这样传递client.service.serviceName(inputDict) ):

{
    'serviceClass': '${serviceName}',
    'vn': '${testVnName}',
    'linkType': 'MULTIPLE_ACCESS',
    'linkTopology': 'POINT_TO_POINT',
    'serviceGuiOptions': {
        'enableBooking': 1, 
        'enableUnManagedTransmitter': 0, 
        'enableCustomSetupParameters': 1
    }, 
    'multicastRequired': 0, 
    'channelCarrier': 0, 
    'qosParameters': {
        'realTime1CirFixed': 6000,
        'realTime1CirPct': 0, 
        'realTime2CirFixed': 0, 
        'realTime2CirPct': 0, 
        'realTime3CirFixed': 0, 
        'realTime3CirPct': 80,
        'criticalData1CirFixed': 0, 
        'criticalData1CirPct': 0, 
        'criticalData1PirFixed': 0, 
        'criticalData1PirPct': 0, 
        'criticalData2CirFixed': 0, 
        'criticalData2CirPct': 0, 
        'criticalData2PirFixed': 0, 
        'criticalData2PirPct': 0, 
        'criticalData3CirFixed': 0, 
        'criticalData3CirPct': 0, 
        'criticalData3PirFixed': 0, 
        'criticalData3PirPct': 0, 
        'bestEffortPirFixed': 0, 
        'bestEffortPirPct': 0
    }, 
    'transportSettings': [
        {'setupParameter': {'key': 'forwardGateway', 'value': 'dialog'}}, 
        {'setupParameter': {'key': 'referenceServiceProfileDomainName', 'value': 'hno'}}
    ]
}

And what I want is (just the problematic part): 我想要的是(只是有问题的部分):

        <transportSettings>
          <setupParameter key="key1" value="val1"/>
          <setupParameter key="key2" value="val2"/>
          <setupParameter key="key3" value="val3"/>
        </transportSettings>

Not sure if you already managed to find the solution yourself. 不知道您是否已经设法自己找到解决方案。

However take a look here: http://docs.python-zeep.org/en/master/datastructures.html 不过请看这里: http : //docs.python-zeep.org/en/master/datastructures.html

<element name='ElementName'>
 <complexType xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <choice maxOccurs="unbounded">
    <sequence>
        <element name="item_1_a" type="string"/>
        <element name="item_1_b" type="string"/>
    </sequence>
    <element name="item_2" type="string"/>
  </choice>
</complexType>

And than nesting your info by adding them to the element itself. 而不是通过将信息添加到元素本身来嵌套信息。 _value_1 refers to the first choice in the parent. _value_1是指父级中的第一选择。

element = client.get_element('ns0:ElementName')
obj = element(_value_1={'item_1_a': 'foo', 'item_1_b': 'bar'})

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM