Skip to content

Instantly share code, notes, and snippets.

@defanator
Created November 16, 2016 12:43
Show Gist options
  • Save defanator/08a8d9dc2e6ecb604c33de4c4b9781b5 to your computer and use it in GitHub Desktop.
Save defanator/08a8d9dc2e6ecb604c33de4c4b9781b5 to your computer and use it in GitHub Desktop.
Test WSGI application using Flask
#!/usr/bin/env python
#
# ./nginman --listen 9999 --py-path `pwd` --py-module flaskapp
from flask import Flask
from flask import request
from werkzeug.debug import get_current_traceback
application = Flask(__name__)
@application.route("/", methods=['GET', 'POST'])
def handler():
try:
args = "REQUEST ARGS: %s" % request.args
body = "REQUETS BODY: %s" % request.data
return "%s\n%s\n" % (args, body)
except Exception,e:
track= get_current_traceback(skip=1, show_hidden_frames=True,
ignore_system_exceptions=False)
track.log()
abort(500)
@application.errorhandler(500)
def internal_error(error):
return "500 error"
if __name__ == "__main__":
application.debug = True
application.config['PROPAGATE_EXCEPTIONS'] = True
application.run(host='127.0.0.1', port=6666)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment