如何在Python中使用zeep传递复杂的参数

时间:2018-08-15 06:43:39

标签: soap wsdl zeep

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

<s:element name="BatchBillPaymentRequest">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="requestData" type="tns:ClientBatchBillPaymentRequestData"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="ClientBatchBillPaymentRequestData">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="CallBackUrl" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="BillItems" type="tns:ArrayOfClientBatchBillPaymentRequestDataItem"/>
</s:sequence>
</s:complexType>
<s:complexType name="ArrayOfClientBatchBillPaymentRequestDataItem">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="ClientBatchBillPaymentRequestDataItem" nillable="true" type="tns:ClientBatchBillPaymentRequestDataItem"/>
</s:sequence>
</s:complexType>
<s:complexType name="ClientBatchBillPaymentRequestDataItem">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="BillId" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="PayId" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="LoginAccount" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="OrderId" type="s:long"/>
<s:element minOccurs="0" maxOccurs="1" name="AdditionalData" type="s:string"/>
</s:sequence>
</s:complexType>
<s:element name="BatchBillPaymentRequestResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="BatchBillPaymentRequestResult" type="tns:ClientBatchBillPaymentResponseData"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="ClientBatchBillPaymentResponseData">
<s:complexContent mixed="false">
<s:extension base="tns:ResponseDataViewModelBase">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="TotalAmount" type="s:long"/>
<s:element minOccurs="1" maxOccurs="1" name="BatchToken" type="s:long"/>
<s:element minOccurs="0" maxOccurs="1" name="BillItems" type="tns:ArrayOfClientBatchBillPaymentResponseDataItem"/>
</s:sequence>
</s:extension>
</s:complexContent>
</s:complexType>

我做了以下事情:

client = Client('https://pec.shaparak.ir/newipgservices/bill/billservice.asmx?WSDL')
result = client.service.BatchBillPaymentRequest(CallBackUrl=_callBackUrl, BillItems=[{'BillId': '7381116907223',
                                                                                    'PayId': '15870210',
                                                                                    'LoginAccount': 'qazwsx',
                                                                                    'OrderId': 1000,
                                                                                    'AdditionalData': '1'}])
print(result)

结果返回此错误:

  

BatchBillPaymentRequest()获得了意外的关键字参数   'BillItems'。签名:`requestData

当我使用此代码而不是上面的代码时:

data = []
data.append({'BillId': '7381116907223', 'PayId': '15870210', 'LoginAccount': 'qazwsx', 'OrderId': 1000, 'AdditionalData': '1'})

wsdl = "https://pec.shaparak.ir/newipgservices/bill/billservice.asmx?WSDL"
client = Client(wsdl=wsdl)
d = dict(CallBackUrl=_callBackUrl, BillItems=data)
result = client.service.BatchBillPaymentRequest(d)
print(result)

在这种情况下,结果为:“输入参数或其某些属性为空”

webservice链接为:webservice link 方法是:method

如果任何人都知道如何在zeep中使用WSDL中的上述类型,我将不胜感激。谢谢。

1 个答案:

答案 0 :(得分:1)

通过此代码解决了问题:

from zeep import Client

data = []
data.append(
    {'BillId': '7381116907223',
     'PayId': '15870210',
     'LoginAccount': 'qazwsx',
     'OrderId': '1000',
     'AdditionalData': '5'})

client = Client(wsdl=_webservice)

d = {
    'CallBackUrl': 'myweb.ir',
    'BillItems': {
        'ClientBatchBillPaymentRequestDataItem': data
    }
}
result = client.service.BatchBillPaymentRequest(d)
print(result)