Call webService using Python+flask

I built a website by learning that Flask Web (is the book whose cover is a dog). On the login page, I need to call the interface provided by WebService. Another developer on our side gave me an WebService interface for me to call, but I don"t know how to call it. I hope you can help me see how the following data is called through Python.

the following is an example of SOAP 1.2 requests and responses. The placeholder displayed needs to be replaced with the actual value.

POST /MemberService.asmx HTTP/1.1
Host: 114.55.172.*
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.*.com/MemberLogin"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <MemberLogin xmlns="http://www.*.com/">
      <sCondition>string</sCondition>
      <sPassword>string</sPassword>
    </MemberLogin>
  </soap:Body>
</soap:Envelope>


HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <MemberLoginResponse xmlns="http://www.*.com/">
      <MemberLoginResult>
        <MebID>int</MebID>
        <CreateTime>dateTime</CreateTime>
        <State>NotActive or Active or Vain</State>
        <StayPlaceID>int</StayPlaceID>
        <MebTypeName>string</MebTypeName>
        <SellerName>string</SellerName>
      </MemberLoginResult>
    </MemberLoginResponse>
  </soap:Body>
</soap:Envelope>

import requests

url = "/login"

payload = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n  <soap:Body>\n    <MemberLogin xmlns=\"http://www.*.com/\">\n      <sCondition>string</sCondition>\n      <sPassword>string</sPassword>\n    </MemberLogin>\n  </soap:Body>\n</soap:Envelope>"
headers = {
    'cache-control': "no-cache",
    'postman-token': "2b4bb59b-2d29-17a9-3bfd-986d15597e40"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

this is just using Python to manipulate XML.

Menu