how to prepare a soap request using zeep?

  • Last Update :
  • Techknowledgy :

far Dec 13, 2020 at 9:46 am the is not working Reply Mohit Budakoti (Moderator) Dec 17, 2020 at 8:20 am Hello  Did you tried to copy and paste this url into web browser window. Did you see xml file eg:, if not then its server problem or your network issue. Reply ,Zeep detects the xml schema from the wsdl file that is passed while creating the client object. Wsdl(Web Service Description Language) contains the required description about the endpoint. It contains the list of operations available and also states the parameters that each operation requires. Zeep uses this information to map the passed request  dictionary to the corresponding xml.,Working with SOAP based web services can sometimes be a time taking task when you have to write the complete XML for making API requests and then parse the response xml to fetch the desired results. That’s a headache right? Well, that’s when zeep comes into play. Zeep is a pure-python module. The best thing about Zeep is that you don’t have to write the XML at all. You just create a dictionary with all the relevant request data, and it will create the XML for you.,As I mentioned above, you just need to pass the request parameters as a standard python dictionary and zeep will internally convert it to the final xml.

The first thing that you’ll need to do is, install the zeep python library as:

pip install zeep

Now, in your python code, you’ll need to import Client from zeep and then instantiate the same by passing the wsdl url in it as shown below:

from zeep
import Client
from zeep import Client
wsdl = ""
client = Client(wsdl)
from zeep import Client
from requests import Session
from requests.auth import HTTPBasicAuth
from zeep.transports import Transport
wsdl = <wsdl_url>
   session = Session()
   session.auth = HTTPBasicAuth(<username>, <password>)
wsdl = <wsdl_url>
session = Session()
session.auth = HTTPBasicAuth(<username>, <password>)
#An additional argument 'transport'
is passed with the authentication details
client = Client(wsdl, transport = Transport(session = session))

Suggestion : 2

Zeep inspects the WSDL document and generates the corresponding code to use the services and types in the document. This provides an easy to use programmatic interface to a SOAP server.,The WSDL used above only defines one simple function (Method1) which is made available by zeep via client.service.Method1. It takes two arguments and returns a string. To get an overview of the services available on the endpoint you can run the following command in your terminal.,Parsing the XML documents is done by using the lxml library. This is the most performant and compliant Python XML library currently available. This results in major speed benefits when processing large SOAP responses.,Note that unlike suds, zeep doesn’t enable caching of the wsdl documents by default. This means that everytime you initialize the client requests are done to retrieve the wsdl contents.

from zeep
import Client

client = Client('')
result = client.service.ConvertSpeed(
   100, 'kilometersPerhour', 'milesPerhour')

assert result == 62.137
pip install zeep
pip install lxml == 4.2 .5 zeep
pip install zeep[xmlsec]
pip install zeep[async]
python -mzeep <wsdl>

Suggestion : 3

I found a tutorial here that got me onto the right track. Here's my code:

from zeep
import Client, Settings

#Creation of headerArr is excluded as it 's not relevant to the xml produced
headerArr = {}
settings = Settings(strict = False, xml_huge_tree = True, extra_http_headers = headerArr)
client = Client('DiscussionCorrespondence/wsdls/DiscussionCorrespondence.wsdl',
   settings = settings)
requestData = {
   'Transaction': {
      'DiscussionTransactionBody': {
         'TransactionContentDetails': {
            'TransactionCode': 'Get Discussion List',
            'TransactionData': {
               'DiscussionList': {
                  'DiscussionListDetails': {
                     'DiscussionCreationDateFrom': '2015-02-10',
                     'DiscussionCreationDateTo': '2015-02-10',
res = client.service.getDiscussionList( ** requestData)

The prettified XML request sent (from a debug log) is:

<soap-env:Envelope xmlns:soap-env="">
      <ns0:getDiscussionList xmlns:ns0="">
         <ns1:Transaction xmlns:ns1="">
                  <ns1:TransactionCode>Get Discussion List</ns1:TransactionCode>

Suggestion : 4

A fast and modern Python SOAP client, A modern/fast python SOAP client based on lxml / requests , A modern/fast python SOAP client based on lxml / requests , Python 99.9%

pip install zeep
from zeep
import Client

client = Client('tests/wsdl_files/example.rst')
pip install zeep
from zeep
import Client

client = Client('tests/wsdl_files/example.rst')

To quickly inspect a WSDL file use:

python -m zeep <url-to-wsdl>