Python suds I am unable to output the Operation in a file from a WSDL

41 views Asked by At

I am trying to output a XML operation from a WSDL in a XML file but i am not getting any output, and how do i find what is the proper attribute my operation has or from the wsdl? I would like to display the XML request without needing to input any parameters which similar to the SoapUI request editor.

from suds.client import Client
import xml.etree.ElementTree as ET

wsdl_url = 'https://sample.com/ccx/service/services_1/Sample_Service/v69.0?wsdl'
client = Client(wsdl_url)

operation = None
for port_type in client.wsdl.types:
    if hasattr(port_type, "ports"):
        for port in port_type.ports:
            binding = port.binding
            for op in binding._operations:
                if op.name == 'AddUpdate_Sample_Population':
                    operation = op
                    break
            if operation:
                break
    if operation:
        break

if operation is not None:
    request = operation.build()
    print(request)

#AddUpdate_Payroll_Payee_FICA_Medicare
if operation is not None:
    request = operation.build()
    root = ET.fromstring(request)
    tree = ET.ElementTree(root)
    tree.write("xml_output.xml")

I suspected that hasattr didnt have the right attribute, ie: "ports" but how do i find out what is my common attribute in all my operations within the wsdl? The code ran successfully but no print output or file being written.

0

There are 0 answers