Forums

Need debug tip for Flask app

I'm working with Flask on Pythonanywhere. I have got a routine processing a POSt request. PA is returning HTTP 200, so the Flask App is working. I've got a problem in my own coding though, and I would like to see request.body. How do I print this to a log or return the value? I've tried "return request.body" and I don't see anything returned, however I suppose Body could be blank. I'm using Hurl for testing though and I am setting a post body.

Any tips are much appreciated.

if you print to stderr, it will end up in the error logs which are linked from the Web tab:

print >> sys.stderr, "debugging"
print >> sys.stderr, request
print >> sys.stderr, request.body

Thank you Harry for the quick support! This solution works for me. The one piece of code that also needs to be included is "import sys".

For those copying/pasting, be sure to change request.body to what you want, perhaps request.data or request.json.