如何使用zeep生成List <string>?

时间:2019-01-02 12:16:28

标签: python soap zeep

我正在使用Python库zeep与SOAP服务进行通信。文档中必需的参数之一是List<String>类型,在WSDL中,我发现了这一点:

<xs:element minOccurs="0" maxOccurs="1" name="IncludedLenders" type="tns:ArrayOfString"/>

我相信AraryOfString的定义是:

<xs:complexType name="ArrayOfString">
  <xs:sequence>
    <xs:element minOccurs="0" maxOccurs="unbounded" name="string" nillable="true" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

如何使zeep生成该值?我尝试过:

"IncludedLenders": [
  "BMS",
  "BME"
]

但是会生成:

                <ns0:IncludedLenders>
                    <ns0:string>BMS</ns0:string>
                </ns0:IncludedLenders>

代替:

                <ns0:IncludedLenders>
                    <ns0:string>BMS</ns0:string>
                    <ns0:string>BME</ns0:string>
                </ns0:IncludedLenders>

任何想法如何产生后代?

1 个答案:

答案 0 :(得分:0)

我想通了。首先,我需要提取ArrayOfString类型:

array_of_string_type = client.get_type("ns1:ArrayOfString")

然后以这种方式创建它:

"IncludedLenders": array_of_string_type(["BMS","BME"])