POST flask server with XML from python POST flask server with XML from python flask flask

POST flask server with XML from python


First, i would add -H "Content-Type: text/xml" to the headers in the cURL call so the server knows what to expect. It would be helpful if you posted the server code (not necessarily everything, but at least what's failing).

To debug this i would use

@app.before_requestdef before_request():    if True:        print "HEADERS", request.headers        print "REQ_path", request.path        print "ARGS",request.args        print "DATA",request.data        print "FORM",request.form

It's a bit rough, but helps to see what's going on at each request. Turn it on and off using the if statement as needed while debugging.

Running your request without the xml header in the cURL call sends the data to the request.form dictionary. Adding the xml header definition results in the data appearing in request.data. Without knowing where your server fails, the above should give you at least a hint on how to proceed.

EDIT referring to comment below:

I would use the excellent xmltodict library. Use this to test:

import xmltodict@app.before_requestdef before_request():    print xmltodict.parse(request.data)['xml']['From']

with this cURL call:

curl -X POST -d '<xml><From>Jack</From><Body>Hello, it worked!</Body></xml>' localhost:5000 -H "Content-Type: text/xml"

'Jack' prints out without issues.

Note that this call has been modified from your question- the 'xml' tag has been added since XML requires a root node (it's called an xml tree for a reason..). Without this tag you'll get a parsing error from xmltodict (or any other parser you choose).