Jan 14, 2023 5:27 PM

How to do SOAP API requests in Python

External YouTube Channel

In this video I will show you how to do SOAP requests in Python with anonymous and basic authentication. Join this channel membership to get access to all the r

There are several libraries in Python that allow you to make SOAP requests. One popular library is suds-py3, which provides a lightweight SOAP client for Python. Here's an example of how to use the library to make a SOAP request:

from suds.client import Client

url = "http://www.example.com/service?wsdl"
client = Client(url)
result = client.service.MethodName(param1, param2)
print(result)

In this example, url is the WSDL (Web Service Definition Language) file of the SOAP service you want to call, MethodName is the name of the method you want to call on the service, and param1 and param2 are the parameters you want to pass to the method. The call to client.service.MethodName(param1, param2) will return the result of the SOAP request.

You can also use zeep library which is more feature rich in making soap requests in python. Here's an example of how to use it

from zeep import Client

wsdl = 'http://example.com/soap?wsdl'
client = Client(wsdl)
result = client.service.method_name(param1=arg1, param2=arg2)

where wsdl is the url of the WSDL file, method_name is the function you want to call, and param1=arg1, param2=arg2 are the arguments you want to pass to the function.

Keep in mind that you will have to install these libraries first by running pip install suds-py3 or pip install zeep in your command line or terminal.