ServerBeep.com is in ongoing development process. To meet your requirements we try to do our best to provide the best and the simplest website and monitoring service. This short post is dedicated to debbuging HTTP requests with Flask and netcat.
Ok, so we need to see what the webserver gets. With Flask it’s pretty simple. Flask is light but power Python framework built on top of Werkzeug and has a lot of extensions and features. It’s not so featured framework as Django but for simple applications it fits very well. (Before we were adepts of web.py and were quite happy with it. Now some of our internal applications are still powered with it, but Flask seems to have more active community and is under more dynamic development at the moment). This a complete code of how to get a request as Flask it sees:
from flask import Flask, request app = Flask(__name__) @app.route('/', methods=['GET', 'POST']) def hello_world(): from pprint import pprint pprint (request.form) # If you need headers just comment out next line. # pprint (request.headers) return 'UP' if __name__ == '__main__': app.debug = True app.run()
And this is it. By default Flask application waits for the requests on port 5000. So now you just need to send a request to 127.0.0.0:5000.
Next way to see how your request is look like is netcat. It’s high featured tool sometimes called Swiss-army knife for TCP/IP. Here’s how to get raw request:
nc -l 5000
Now netcat will redirect everything it gets to output so you will be able to check if you are doing everything right. The same way, just send you requests to 127.0.0.0:5000.
If you don’t have netcat and/or Flask installed you can do this this way on Fedora or Centos:
yum install python-flask
yum install nc