Skip to content Skip to sidebar Skip to footer

Using Python Requests Library

Hey all you loved peoples, I have another one for you. I'm using django, requests, and google checkout. I am at the point of sending xml to Google checkout right. All is well EXCEP

Solution 1:

The problem seems to be that you are trying to parse not only the XML, but the content-type header as well, and the parser is complaining as it is expecting a XML root element, not the "Content-Disposition" string.

This is strange, because if you do something like:

response = requests.post(some_url, ...)

The response.text is not supposed to include headers. If you are using the raw response, switch to response.text instead.

If you are getting the headers anyway, get rid of everything before the first blank line (\r\n\r\n) before feeding it to the parser:

import re
xml = '\n'.join(re.split(r'\r?\n\r?\n', raw_response)[1:])

Post a Comment for "Using Python Requests Library"