【发布时间】:2017-08-28 07:45:58
【问题描述】:
我正在使用zeep python package 以便通过接受“ArrayofInt”类型参数的 SOAP 调用函数。
传递“普通”整数数组不起作用...解决方法是使用 for 循环遍历数组元素并逐个发送元素,但这不是我拥有的最干净的代码曾经写过:)
有什么建议吗?
【问题讨论】:
标签: python web-services soap xsd zeep
我正在使用zeep python package 以便通过接受“ArrayofInt”类型参数的 SOAP 调用函数。
传递“普通”整数数组不起作用...解决方法是使用 for 循环遍历数组元素并逐个发送元素,但这不是我拥有的最干净的代码曾经写过:)
有什么建议吗?
【问题讨论】:
标签: python web-services soap xsd zeep
这个answer 会帮你解决的。
使用 Zeep 的 client.get_type 函数创建一个空的 Zeep ArrayOfInt 对象,然后通过它循环您的数组。
client = Client(soap_url)
test_list = [1,2,3,4]
emptyArrayPlaceholder = client.get_type('ns0:ArrayOfInt')
options = emptyArrayPlaceholder()
for el in test_list:
options['int'].append(el)
【讨论】:
如果您在 SOAP 服务中的方法接受整数数组作为参数,那么您可以尝试这种方式:
clientInt = Client(wsdl)
list_int=[1,2,3]
dict_int = {"ArrayOfInteger":{"integer":list_int}}
clientInt.service.getMultipleInt(**dict_int)
当你传递**dict_int作为参数时,python3会解包字典并将字典中的关键字作为函数参数传递。
【讨论】:
如果您无法从 wsdl 检索对象,请尝试以下操作:
client = Client(soap_url)
test_list = [1,2,3,4]
client.service.ServiceName({"foo": {"int": test_list}})
【讨论】: