Thursday, 15 August 2013

python - Reading POST body with bottle.py -



python - Reading POST body with bottle.py -

i having problem reading post request bottle.py.

the request sent has text in body. can see how made here on line 29: https://github.com/kinetica/tries-on.js/blob/master/lib/game.js.

i can see how reading done on node.js based client here on line 4: https://github.com/kinetica/tries-on.js/blob/master/masterclient.js.

however, haven't been able mimic behaviour on bottle.py based python client. docs here http://bottlepy.org/docs/0.11/api.html#bottle.baserequest.body can read raw body file-like object, couldn't info neither using loop on request.body, nor using request.body's readlines method.

i'm handling request in function decorated @route('/', method='post'), , requests arrive correctly.

thanks in advance,

martín coll.

edit:

my hole script is:

from bottle import route, run, request @route('/', method='post') def index(): l in request.body: print l print request.body.readlines() run(host='localhost', port=8080, debug=true)

did seek simple postdata = request.body.read() ?

following illustration shows reading posted info in raw format using request.body.read()

it prints log file (not client) raw content of body.

to show accessing of form properties, added returning "name" , "surname" client.

for testing, used curl client command line:

$ curl -x post -f name=jan -f surname=vlcinsky http://localhost:8080

the code works me:

from bottle import route, run, request @route('/', method='post') def index(): postdata = request.body.read() print postdata #this goes log file only, not client name = request.forms.get("name") surname = request.forms.get("surname") homecoming "hi {name} {surname}".format(name=name, surname=surname) run(host='localhost', port=8080, debug=true)

python post python-2.7 bottle

No comments:

Post a Comment