0

I created request in my python code, that gives me response like bellow:

<tasks>
    <task>
        <description>description</description>
        <name>test task 1</name>
        <sysID>410d6c0bc0a801c901838d8ac43b3279</sysID>
        <type>Windows</type>
        <version>2</version>
    </task>
    <task>
        <description>description</description>
        <name>test task 2</name>
        <sysID>410d6880c0a801c90196685fcc1ecb47</sysID>
        <type>Windows</type>
        <version>9</version>
    </task>
</tasks>

It lists all the tasks.

But I need to get just the list of the names of the tasks. Is there a way how to specify it in request? Or do I need to parse it after?

Or more general question: is there a way how to define in a request which tags and attributes will be returned as response?

My request now:

response = req.post(uac_path, auth=HTTPBasicAuth(user, pw), 
headers=headers, data=prop_params, verify=True)

2 Answers 2

1

It's the server's responsibility to decide what to return, rather than the client's. Unless the server gives you some way to specify what should be returned (for instance if it's a GraphQL API) you'll need to parse the response yourself.

Sign up to request clarification or add additional context in comments.

Comments

1

you need to parse the response first. there are several packages in Python to parse XML:

 - xml.dom
 - xml.dom.minidom
 - xml.dom.pulldom
 - xml.sax
 - xml.parser.expat
 - xml.etree.ElementTree

you can choose any one of them or other thirdparty tools in Python

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.