What is Werkzeug?

From the official documentation :

Werkzeug is a WSGI utility library for Python.

However, when I launch my Flask web application, I notice that the response header from the server contains:

HTTP/1.0 200 OK Content-Type: text/html; charset=utf-8 Content-Length: 13 Server: Werkzeug/0.11.9 Python/2.7.10 Date: Tue, 03 May 2016 12:50:08 GMT 

In the fourth line, the server mentions Werkzeug , but what exactly is Werkzeug , is it a web server like Apache ?

+34
python flask web-services werkzeug wsgi server
source share
5 answers

No, this is not a web server like Apache. This is the CGI library. Since Apache (or your Flask application) probably uses the library to serve some HTTP requests, it probably adds this header to the response.

+7
source share

No that's not

Werkzeug (WSGI library) is like a communicator between your python code and the nginx / apache http server

Here is a complete example of using Werkzeug WSGI:

WSGI has two sides: the "server" or "gateway" (often a web server such as Apache or Nginx), and the side "application" or "wireframe" (the Python script itself). To process the WSGI request, the server side runs the application and provides environmental information and a callback on the application side. Application processes a request that returns a response to the server side using a callback function was provided.

Between the server and the application, there may be WSGI middleware that implements both sides of the API. The server receives a request from the client and forwards it to the middleware. After processing, it sends a request to the application. The application response is sent to the server and, ultimately, to the client. There may be several intermediaries that make up the WSGI-compatible application stack.

Hope this helps

+23
source share

Werkzeug is primarily a library, not a web server, although it provides a simple web server for development purposes. It is this development server that provides the Server: header.

To go to more detail:

First, let's talk about WSGI. There are many web servers like Apache, Nginx, Lighttpd, etc. There are also several web frameworks written in Python, for example. Django, Infusion, Tornado, Pyramid, etc. It would be very convenient if they were all compatible. This is where the WSGI comes in. The idea is this:

  • When responding to a client’s HTTP request, two parties are involved: the web server and the web application . The server processes the intricacies of network connections, receives a request, and sends a response. The application receives the request data, processes it and creates a response for sending by the server back.

  • If you want to write a Python web application, make sure that it has a callable object (for example, a function) that accepts certain parameters for HTTP headers, input form data, environment variables, etc.

  • If you want to write a web server that serves Python applications, force it to call this called object from the application every time an HTTP request arrives.

  • The WSGI specification (in PEP 3333 ) defines exactly what the parameters for this called object should be and what the return value should be so that each server knows how to communicate with each application and vice versa.

So, we know that every web application must provide this called object and be able to process certain parameters that it receives. Every application should do this ... It sounds like a good opportunity to use the library. Werkzeug is a library.

Werkzeug provides a set of utilities for developing applications compatible with WSGI. These utilities perform functions such as parsing headers, sending and receiving cookies, providing access to form data, creating redirects, creating error pages when an exception occurs, even providing an interactive debugger that runs in the browser. It is really quite comprehensive. Flask is then built on this foundation (and Jinja, Click, etc.) to provide a complete web environment.

So, if Werkzeug is a library for applications, why is it displayed in the server header?

Werkzeug also has a module for the server role. This is for convenience only.

Installing and setting up a full-fledged web server, such as Apache or Nginx, requires a lot of effort and is almost certainly unnecessary due to the fact that you are testing your application on your own development platform. For this reason, Werkzeug provides a development server: a simple web server that can be launched with a single command and with little or no configuration. When you do flask run (or werkzeug.serving.run_simple() ), you get exactly this development server. And the Server: header Server: for the development server - & - you guessed it - Werkzeug/<version> Python/<version> .

This server is not intended for production use. At least according to the docs, it doesn't scale very well. But I won’t be surprised if there are other problems, such as security.

+23
source share

Because it is not.

In your setup, you most likely use the "development server" ( run_simple function) for testing. Thus, it is used in this case as a (very) poor Apache person, but only in the sense that he is able to correctly respond to HTTP requests.

If you check the documents http://werkzeug.pocoo.org/docs/serving/ , you will see the following note:

The development server is not intended for use in production systems. It was designed specifically for development purposes and does not work well under high load. For deployment installations, view the application deployment pages.

+12
source share

Flask Python uses Werkzeurg as a web server for testing

-2
source share

All Articles