Answer the question
In order to leave comments, you need to log in
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>
Answer the question
In order to leave comments, you need to log in
If there are not many types of requests and the requests are not complex, then IMHO it is better to make an oak
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)
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 questionAsk a Question
731 491 924 answers to any question