N
N
newbie_python2020-08-22 21:48:52
Python
newbie_python, 2020-08-22 21:48:52

How to pull out the value received in the response to the request?

Hello! I send a SOAP request and get a response:

<?xml version='1.0' encoding='UTF-8'?>
  <soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
      <Response
        xmlns="URL">
        <message>ba53cf44-5610-40e3-8def-a8b031f1f930</message>
      </Response>
    </soapenv:Body>
  </soapenv:Envelope>


How can I extract the value from the "message" tag received in the response and store it in a separate variable? Below is the code I am using.

import requests
url="URL"
#headers = {'content-type': 'application/soap+xml'}
headers = {'content-type': 'text/xml'}
body = """MY_SOAP_REQUEST"""

response = requests.post(url,data=body.encode('utf-8'),headers=headers)
answer = response.content.decode('UTF-8')

print(response)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ronald McDonald, 2020-08-22
@newbie_python

Take and parse XML.
This is what happened to me: https://codecamp.ru/blog/python-manipulating-xml/
You can "head on" find a tag in the response <message>and pull out the value through regexps or stupidly with find().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question