Search code examples
pythonsoapwsdlzeep

SOAP request with Zeep (Python)


I am trying to send SOAP request using zeep module in python. python -mzeep XXXXXXXX.wsdl returns following:

Prefixes:

 xsd: http://www.AA.org/2003/XMLSchema
 ns0: http://www.bbbb.com/PM/BLS

Global elements:

 ns0:GetBalReq(header: ns0:RequestHeader, custId: xsd:string, customAvpList: ns0:AttributeValuePairList)
 ns0:GetBalResp(nalId: xsd:string, custId: xsd:string, custRole: xsd:string, nalType: xsd:string, bal: ns0:BalDetailsList, customAvpList: ns0:AttributeValuePairList)

Global types:

 xsd:anyType
 ns0:AttributeValuePair(attribute: xsd:string, value: xsd:string)
 ns0:AttributeValuePairList(item: ns0:AttributeValuePair[])
 ns0:BalDetailsList(item: ns0:BalDetails[])
 ns0:RequestHeader(auditInfo: xsd:string, transactionId: xsd:string)
 xsd:string

Bindings:

 Soap11Binding: {http://www.bbbb.com/PM/BLS}BLS

Service: BLS

 Port: BLS (Soap11Binding: {http://www.bbbb.com/PM/BLS}BLS)

     Operations:
        getBalReq(header: ns0:RequestHeader, custId: xsd:string, customAvpList: ns0:AttributeValuePairList) -> nalId: xsd:string, custId: xsd:string, custRole: xsd:string, nalType: xsd:string, bal: ns0:BalDetailsList, customAvpList: ns0:AttributeValuePairList

just by following:

from zeep import Client
client = Client('XXXXXXXX.wsdl')
client.service.getBalReq(custId='12345678')

I get following error:

"Missing element %s" % (self.name), path=render_path

zeep.exceptions.ValidationError: Missing element header (GetBalReq.header)

Now I have been breaking by brain for last 2 days how to make this work, how to send proper request in order to get valid response, read zeep documentation, forums etc etc but just can't figure it out. Any idea for proper code?


Solution

  • You have to pass the parameter 'header' to the method 'getBalReq' as below.

        from zeep import Client
        client = Client('XXXXXXXX.wsdl')
    
        header_request = client.get_type('ns0:RequestHeader')
        header = header_request(auditInfo = your_auditInfo,transactionId = your_transactionId)
        client.service.getBalReq(header=header, custId='12345678', customAvpList = your_customAvpList)
    

    If customAvpList is an optional parameter, you can ignore it.