There are SOAP requests of this type:

<?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 the address of the form: http: // IP: Port / wsdl

Share an example of how you can implement such a request through Python?

Or a link to any material on this issue?

  • one
  • Yes, I did something like this, but I get an incomprehensible answer from the server: "No satisfactory results were found" - 8toni8
  • Therefore, I need a working example of a request for a server ... In order to be able to verify that I was not mistaken in the code and the server really does not correctly respond to my request. The fact is that the server does not belong to me and I am not sure about the correctness of its work :( - 8toni8
  • I figured out how to send a request using SoapUI ... The server still answered :) But when I send a request using Python, I get only a list of methods in response, as if no request is being sent, but just go to the / wsdl page . It turns out that the code does not work: ( - 8toni8

1 answer 1

Damn, it turned out all the same :) So I thought the snag was that the server administrator gave me the wrong address to send the request :( As a result, the server with the prefix / wsdl received a list of supported methods, including was specified and the address for the request.

But the program itself for the request:

 import requests endpoint = "здесь адрес для запроса" body="""здесь запрос""" 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) print(response.content) 
  • 2
    session.headers.update({"Content-Length": str(len(body))}) -> session.headers["Content-Length"] = len(body) . Kst, requests must fill in the "Content-Length" - gil9red
  • I do not understand, in a sense? You hint at what else you had to add: "Content-Length =" is the query here? "? - 8toni8
  • one
    No, I wrote that your code, which I quoted in the commentary, can be replaced with simpler codes, and ideally, remove them altogether. requests must add the Content-Length header to the request - gil9red
  • I still do not understand what you mean? In place of my code, use this "session.headers.update ({" Content-Length ": str (len (body))}) -> session.headers [" Content-Length "] = len (body)"? - 8toni8
  • one
    Yeah, I indicated a line of code that can be simplified without losing its performance. And after added that it can not be specified, because requests anyway fill it up - gil9red