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

How to pass complex arguments with zeep in Python

我有一个包含如下复杂类型的 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)

结果return这个错误:

BatchBillPaymentRequest() got an unexpected keyword argument 'BillItems'. Signature: `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)

在这种情况下,结果是:"The input parameter or some of its properties is empty"

网络服务 link 是:webservice link 方法是:method

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

已解决问题,通过此代码:

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)