如何指定xsi:type zeep python [英] how to specify xsi:type zeep python

查看:190
本文介绍了如何指定xsi:type zeep python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用适用于python的zeep SOAP客户端,尝试将一些数据获取到某些wsdl_address.我现在有以下内容:

Im using zeep SOAP client for python, trying to get some data to some wsdl_address. i now have following:

ambCase = {'data1':'value1',
       'data2':'value2'}
client = zeep.Client(wsdl=WSDL_Address)
result = client.service.MethodName(GUID, {'CaseDto':ambCase})

其中ambCase是我要获取到服务器的数据. MethodName方法需要2个参数:GUID令牌(这没问题)和具有指定xsi:type属性的ambCase对象(在我的情况下,它应该是"CaseAmb"),但我无法使其正常工作,但失败错误: zeep.exceptions.Fault:异常str()失败

where ambCase is data i want to get to the server. MethodName method requires 2 parameters: GUID token(which works no problem), and ambCase object with specified xsi:type attribute(in my case it should be 'CaseAmb'), and i can't get it to work, it fails with an error: zeep.exceptions.Fault: exception str() failed

代码生成以下xml(标头除外):

code above produces this xml(excepting headers):

<soap-env:Body>
<ns0:AddCase xmlns:ns0="http://tempuri.org/">
  <ns0:guid>00000000-0000-0000-0000-000000000000</ns0:guid>
  <ns0:caseDto/>
</ns0:AddCase>

我对SOAP和zeep还是很陌生,所以,有人可以帮忙吗?

I'm pretty new to SOAP and zeep, so, can anyone help?

推荐答案

通过反复试验,以下组合有效:

By trial and error the following combination worked:

objectType = client.get_type('ns6:someTypeName') # someTypeName will be in xsi:type attribute
objectWrap = xsd.Element('xmlTagName',objectType) # xmlTagName - name of created xml element
objectValue = objectWrap('param1',param2,param3[0]) # putting actual data values into object
client = zeep.Client(wsdl)
result = client.service.MethodName(objectValue) # calling  some method with your object(with explicitly detrmined type) as param

问题是,如果您将dict作为方法参数传递,则zeep会自己创建该对象(无类型),如果您想确定类型-自己创建该对象

The thing is, if you pass a dict as method param, zeep will create that object himself(without type), if you want to determine type - create that object by yourself

这篇关于如何指定xsi:type zeep python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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