如何从WSDL在Python
问题描述:
使用复杂类型ZEEP我有一个包含像这样一个复杂类型的wsdl:如何从WSDL在Python
<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的SOAP客户端,并希望使用键入作为WSDL中引用的其他方法之一的参数。我似乎无法弄清楚如何使用这种类型。当我通过documentation如何使用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.`
如果有人知道如何从与ZEEP使用WSDL上述类型, 我会很感激。谢谢。
答
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)
您是否设法解决了您的问题?我目前面临类似的问题 – JohnnyQ
对不起,我没有。由于我的产品没有使用SOAP,所以不值得花时间去解决。祝你好运,但。 – user197674