POST flask server with XML from python -


i have flask server , running on pythonanywhere , trying write python script can run locally trigger particular response - lets server time, sake of discussion. there tonnes , tonnes of documentation on how write flask server side of process, non/very little on how write can trigger flask app run. have tried sending xml in form of simple curl command e.g.

curl -x post -d '<from>jack</from><body>hello, worked!</body>' url 

but doesnt seem work (errors referral headers).

could let me know correct way compose xml can sent listening flask server.

thanks,

jack

first, add -h "content-type: text/xml" headers in curl call server knows expect. helpful if posted server code (not everything, @ least what's failing).

to debug use

@app.before_request def 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 bit rough, helps see what's going on @ each request. turn on , off using if statement needed while debugging.

running request without xml header in curl call sends data request.form dictionary. adding xml header definition results in data appearing in request.data. without knowing server fails, above should give @ least hint on how proceed.

edit referring comment below:

i use excellent xmltodict library. use test:

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

with curl call:

curl -x post -d '<xml><from>jack</from><body>hello, worked!</body></xml>' localhost:5000 -h "content-type: text/xml" 

'jack' prints out without issues.

note call has been modified question- 'xml' tag has been added since xml requires root node (it's called xml tree reason..). without tag you'll parsing error xmltodict (or other parser choose).


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -