What exactly is Werkzeug?

Werkzeug is primarily a library, not a web server, although it does provide a simple web server for development purposes. That development server is what’s providing that Server: header. To go into more detail: First, let’s talk about WSGI. There are a bunch of web servers out there, like Apache, Nginx, Lighttpd, etc. There are … Read more

Get raw POST body in Python Flask regardless of Content-Type header

Use request.get_data() to get the raw data, regardless of content type. The data is cached and you can subsequently access request.data, request.json, request.form at will. If you access request.data first, it will call get_data with an argument to parse form data first. If the request has a form content type (multipart/form-data, application/x-www-form-urlencoded, or application/x-url-encoded) then … Read more

Get IP address of visitors using Flask for Python

See the documentation on how to access the Request object and then get from this same Request object, the attribute remote_addr. Code example from flask import request from flask import jsonify @app.route(“/get_my_ip”, methods=[“GET”]) def get_my_ip(): return jsonify({‘ip’: request.remote_addr}), 200 For more information see the Werkzeug documentation.

Configure Flask dev server to be visible across the network

While this is possible, you should not use the Flask dev server in production. The Flask dev server is not designed to be particularly secure, stable, or efficient. See the docs on deploying for correct solutions. The –host option to flask run, or the host parameter to app.run(), controls what address the development server listens … Read more

Get the data received in a Flask request

The docs describe the attributes available on the request object (from flask import request) during a request. In most common cases request.data will be empty because it’s used as a fallback: request.data Contains the incoming request data as string in case it came with a mimetype Flask does not handle. request.args: the key/value pairs in … Read more

tech