Python: SOAP requests, how to make wsdl requests

Hello, I have a wsdl ( https://ws1.bmgconsig.com.br/webservices/SaqueComplementar?wsdl ) and I need to make requests, but I don't know how to handle headers and body based on wsdl.

The header:

{'Date': 'Thu, 04 Apr 2019 12:17:42 GMT', 'Content-Type': 'text/xml;charset=utf-8', 'Vary': 'Accept-Encoding', 'Content-Encoding': 'gzip', 'Connection': 'close', 'Transfer-Encoding': 'chunked'}

My Code:

url = 'https://ws1.bmgconsig.com.br/webservices/SaqueComplementar?wsdl'
headers = {'input name': 'buscarLimiteSaqueRequest'}
params = {informações de login, senha e parâmetros necessários}
r = requests.post(url, headers=headers, data=params )

Returns:

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
     <title>400 Bad Request</title>
     </head><body>
     <h1>Bad Request</h1>
     <p>Your browser sent a request that this server could not understand.<br />
     </p>
     <hr>
     <address>Apache/2.2.15 (Red Hat) Server at slap443.bancobmg.com.br Port 80</address>
     </body></html>

I don't know if 'headers' is set right. I have already read all the documentation of 'requests', but it gives many examples in json (), but this wsdl does not provide support.

If I don't put 'headers', it returns:

    <soapenv:Body>
      <soapenv:Fault>
       <faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode>
       <faultstring>no SOAPAction header!</faultstring>
       <detail>
        <ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">slap443.bancobmg.com.br</ns2:hostname>
       </detail>
      </soapenv:Fault>
     </soapenv:Body>
    </soapenv:Envelope>

I have already used the zeep framework and it worked, but it is very slow, I believe that using 'requests' I get a better performance.

Author: parodi, 2019-04-04

1 answers

Your Server is waiting for a SOAPAction parameter in the header. No request would be:

url = 'https://ws1.bmgconsig.com.br/webservices/SaqueComplementar?wsdl'
headers = {'input name': 'buscarLimiteSaqueRequest', 'SOAPAction ': '<action>'}
params = {informações de login, senha e parâmetros necessários}
r = requests.post(url, headers=headers, data=params )

But in this case you need to know which value to put in place of <action>.

 0
Author: Gean Santos, 2019-06-18 13:55:58