A
A
Anton2018-08-03 06:58:48
Python
Anton, 2018-08-03 06:58:48

Python SOAP client example?

There are SOAP requests like this:

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <NS1:GetVersion xmlns:NS1="urn:DCCIntf-IDCC">
      <user></user>			- имя пользователя
      <pass></pass>			- пароль пользователя
    </NS1:GetVersion>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Which somehow needs to be sent to an address of the form:
http://IP:Port/wsdl
Share an example of how such a request can be implemented using Python?
Or a link to any materials on this issue?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Q
qlkvg, 2018-08-03
@8toni8

If there are not many types of requests and the requests are not complex, then IMHO it is better to make an oak

spoiler
import requests

user = "admin"
password = "password"
endpoint = "http://soap.endpoint"

login_template = """
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <NS1:GetVersion xmlns:NS1="urn:DCCIntf-IDCC">
      <user>{user}</user>			
      <pass>{pass}</pass>			
    </NS1:GetVersion>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
"""
body = body.format(user=user, pass=password)
body = body.encode('utf-8')

session = requests.session()
session.headers = {"Content-Type": "text/xml; charset=utf-8"}
session.headers.update({"Content-Length": str(len(body))})
response = session.post(url=endpoint, data=body, verify=False)

I myself recently tried to make zeep and suds friends with one specific API for half a day, as a result, I spat and for the remaining half a day I did everything on bare requests.

Y
Yan Anisimov, 2018-08-03
@yanchick

The key idea of ​​SOAP is that the spec is given by url with wsdl. There are functions, and parameters and their types. If the task is to brainstorm, then you can write the client yourself and increase the skill on the python. But for production, writing a client yourself is, well, at least not reasonable. And an example of a finished one https://github.com/mvantellingen/python-zeep.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question