如何在Python中使用带有zeep的WSDL使用复杂类型 [英] How to use a complex type from a WSDL with zeep in Python

查看:163
本文介绍了如何在Python中使用带有zeep的WSDL使用复杂类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含如下复杂类型的WSDL:

I have a WSDL that contains a complex type like so:

<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 ,并希望将该类型用作WSDL中引用的其他方法之一的参数.我似乎无法弄清楚如何使用此类型.当我查看文档时,如何使用参考中提到的某些数据结构WSDL,它说要使用client.get_type()方法,所以我做了以下事情:

I have decided to use zeep for the soap client and want to use that type as a parameter to one of the other methods referenced in the WSDL. I can't seem to figure out how to use this type though. When I looked through the documentation on how to use certain data structures referenced in the WSDL, it says to use the client.get_type() method, so I did the following:

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.我还尝试了许多变体,以及尝试使用像这样的字典:

This give an error TypeError: argument of type 'string_array' is not iterable. I also tried many variations of that as well as trying to use a dictionary like so:

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中的上述类型,我将不胜感激.谢谢.

If anyone knows how to use the above type from the WSDL with zeep, I would be grateful. Thanks.

推荐答案

client.get_type()方法返回一个类型构造函数",您以后可用来构造该值.您需要将构造的值分配给一个单独的变量,并在方法调用中使用该变量:

The client.get_type() method returns a 'type constructor' that you can later use to construct the value. You need to assign the constructed value to a separate variable and use that variable in the method invocation:

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)

这篇关于如何在Python中使用带有zeep的WSDL使用复杂类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆