Questions tagged [werkzeug]

Werkzeug is a WSGI utility library for Python. It's widely used and BSD licensed.

Werkzeug is a WSGI utility library for Python. It includes a debugger and fully featured request response headers. Also included is a set of HTTP utilities.

624 questions
38
votes
1 answer

Check if Flask request context is available

I want to log some data from context variables (request, session) when logging during a Flask request, but use default behavior if not. I'm using a try ... except block in logging.formatter. Is there a better way to check for a request…
ubombi
  • 1,115
  • 2
  • 15
  • 30
37
votes
8 answers

How to set up autoreload with Flask+uWSGI?

I am looking for something like uWSGI + django autoreload mode for Flask.
Florian
  • 2,562
  • 5
  • 25
  • 35
35
votes
6 answers

ImportError: cannot import name 'safe_str_cmp' from 'werkzeug.security'

Any ideas on why I get this error? My project was working fine. I copied it to an external drive and onto my laptop to work on the road; it worked fine. I copied it back to my desktop and had a load of issues with invalid interpreters etc, so I made…
prosody
  • 557
  • 1
  • 3
  • 11
33
votes
3 answers

What's the right approach for calling functions after a flask app is run?

I'm a little confused about how to do something that I thought would be quite simple. I have a simple app written using Flask. It looks something like this: from flask import Flask app = Flask(__name__) def _run_on_start(a_string): print…
Edwardr
  • 2,906
  • 3
  • 27
  • 30
31
votes
5 answers

How to apply integration tests to a Flask RESTful API

[As per https://stackoverflow.com/a/46369945/1021819, the title should refer to integration tests rather than unit tests] Suppose I'd like to test the following Flask API (from here): import flask import flask_restful app =…
Kurt Peek
  • 52,165
  • 91
  • 301
  • 526
31
votes
1 answer

AttributeError: 'Context' object has no attribute 'wrap_socket'

I am trying to set up a Flask server that uses an OpenSSL context. However, since I moved the script on a different server, it keeps throwing the following error, no matter if I am using Python 2.7 or 3.4 and no matter which SSL method I chose…
Nils Milchert
  • 313
  • 1
  • 3
  • 5
31
votes
1 answer

X-Forwarded-Proto and Flask

I have precisely the same problem described in this SO question and answer. The answer to that question is a nice work around but I don't understand the fundamental problem. Terminating SSL at the load balancer and using HTTP between the load…
Ben Whaley
  • 32,811
  • 7
  • 87
  • 85
31
votes
7 answers

Custom error message json object with flask-restful

It is easy to propagate error messages with flask-restful to the client with the abort() method, such as abort(500, message="Fatal error: Pizza the Hutt was found dead earlier today in the back seat of his stretched limo. Evidently, the notorious…
Derek
  • 3,295
  • 3
  • 24
  • 31
28
votes
1 answer

Running Flask dev server in Python 3.6 raises ImportError for SocketServer and ForkingMixIn

I am trying to run a basic Flask app using Python 3.6. However, I get an ImportError: cannot import name 'ForkingMixIn'. I don't get this error when running with Python 2.7 or 3.5. How can I run Flask with Python 3.6? from flask import Flask app…
SharpCoder
  • 18,279
  • 43
  • 153
  • 249
28
votes
3 answers

Flask slow at retrieving post data from request?

I'm writing flask application that accepts POST requests with json data. I noticed huge differences in response time based on data size being passed to application. After debugging I narrowed down issue to the line where I was retrieving json data…
marcin_koss
  • 5,763
  • 10
  • 46
  • 65
26
votes
2 answers

What is going on when I set app.wsgi_app = ProxyFix(app.wsgi_app) when running a Flask app on gunicorn?

I built a basic web app using Flask, and was able to run it from a virtual machine using its native http server. I quickly realized that with this set up, requests are blocking (I couldn't make concurrent requests for resources; any new request…
Ashley Temple
  • 311
  • 1
  • 4
  • 8
25
votes
2 answers

Flask/Werkzeug, how to return previous page after login

I am using the Flask micro-framework which is based on Werkzeug, which uses Python. Before each restricted page there is a decorator to ensure the user is logged in, currently returning them to the login page if they are not logged in, like so: #…
Jon Cox
  • 10,622
  • 22
  • 78
  • 123
21
votes
2 answers

Dynamic form fields in flask.request.form

I've looked through the documentation, but for the life of me, I can't figure out how the request.form object in Flask is populated. The documentation says that it's filled with parsed form data from POST or PUT requests, but my form is dynamic so…
Chase Sandmann
  • 4,795
  • 3
  • 30
  • 42
20
votes
3 answers

Get IP Address when testing flask application through nosetests

My application depends on request.remote_addr which is None when i run tests through nosetests which uses app.test_client().post('/users/login', ....). How can I emulate an IP (127.0.0.1 works fine) when I run tests? I've tried setting environment…
moodh
  • 2,661
  • 28
  • 42
19
votes
3 answers

Flask/Werkzeug how to attach HTTP content-length header to file download

I am using Flask (based on Werkzeug) which uses Python. The user can download a file, I'm using the send_from_directory-function. However when actually downloading the file, the HTTP header content-length is not set. So the user has no idea how big…
Jon Cox
  • 10,622
  • 22
  • 78
  • 123
1
2
3
41 42