我有一个包含复杂类型的 WSDL,如下所示:
<xsd:complexType name="string_array">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="xsd:string[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
我决定使用zeep https://github.com/mvantellingen/python-zeep对于 SOAP 客户端,并希望将该类型用作 WSDL 中引用的其他方法之一的参数。但我似乎不知道如何使用这种类型。当我翻阅文档 http://docs.python-zeep.org/en/master/datastructures.html关于如何使用 WSDL 中引用的某些数据结构,它说使用client.get_type()
方法,所以我做了以下事情:
wsdl = "https://wsdl.location.com/?wsdl"
client = Client(wsdl=wsdl)
string_array = client.get_type('tns:string_array')
string_array('some value')
client.service.method(string_array)
这给出了一个错误TypeError: argument of type 'string_array' is not iterable
。我还尝试了许多变体,并尝试使用像这样的字典:
client.service.method(param_name=['some value'])
这给出了错误
ValueError: Error while create XML for complexType '{https://wsdl.location.com/?wsdl}string_array': Expected instance of type <class 'zeep.objects.string_array'>, received <class 'str'> instead.`
如果有人知道如何将 WSDL 中的上述类型与 zeep 一起使用,我将不胜感激。谢谢。
client.get_type() 方法返回一个“类型构造函数”,您稍后可以使用它来构造该值。您需要将构造的值分配给一个单独的变量,并在方法调用中使用该变量:
wsdl = "https://wsdl.location.com/?wsdl"
client = Client(wsdl=wsdl)
string_array_type = client.get_type('tns:string_array')
string_array = string_array_type(['some value'])
client.service.method(string_array)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)