0

I fetch some data from an api with below code

headers = {
    'Authorization': "Basic XXXXXXXXX",
    'Accept': 'application/xml',
}

resp = requests.get('https://api_request', headers=headers)

I receive a correct response from the API (code 200) but content is in bytes format so not easy to read. Printing the resp.content gives:

print(resp.content)
b'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><legalEntity xmlns="http://XXXX.io"><status>AGT_VALIDATED</status><id><code>140012</c.........

Is there a way to convert this in a easy to manipulate format so that I can extract the specific info I need?

4

1 Answer 1

1

Thanks for your comments. Below the solution I went for.

mydict = xmltodict.parse(resp.content.decode('utf-8'))
Sign up to request clarification or add additional context in comments.

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.