Forums

CSRF timeouts

Hi,

I'm getting this error when running WTForms:

**> Traceback (most recent call last): File "/bin/user_wsgi_wrapper.py",

line 154, in call app_iterator = self.app(environ, start_response) File "/home/pv/.local/lib/python3.5/site-packages/flask/app.py", line 2000, in call return self.wsgi_app(environ, start_response) File "/home/pv/.local/lib/python3.5/site-packages/flask/app.py", line 1991, in wsgi_app response = self.make_response(self.handle_exception(e)) File "/home/pv/.local/lib/python3.5/site-packages/flask/app.py", line 1567, in handle_exception reraise(exc_type, exc_value, tb) File "/home/pv/.local/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise raise value File "/home/pv/.local/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app response = self.full_dispatch_request() File "/home/pv/.local/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/pv/.local/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/pv/.local/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise raise value File "/home/pv/.local/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request rv = self.dispatch_request() File "/home/pv/.local/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request return self.view_functionsrule.endpoint File "/home/pv/phil_web/flask_app.py", line 58, in index form = NameForm() File "/usr/local/lib/python3.5/dist-packages/wtforms/form.py", line 212, in call return type.call(cls, args, kwargs) File "/usr/local/lib/python3.5/dist-packages/flask_wtf/form.py", line 96, in init args, kwargs) File "/usr/local/lib/python3.5/dist-packages/wtforms/ext/csrf/form.py", line 22, in init self.csrf_token.current_token = self.generate_csrf_token(csrf_context) File "/usr/local/lib/python3.5/dist-packages/flask_wtf/form.py", line 101, in generate_csrf_token return generate_csrf(self.SECRET_KEY, self.TIME_LIMIT) File "/usr/local/lib/python3.5/dist-packages/flask_wtf/csrf.py", line 43, in generate_csrf raise Exception('Must provide secret_key to use csrf.') Exception: Must provide secret_key to use csrf.

"Must provide secret_key to use csrf" suggests that there's a secret key setting somewhere that you need to set. Check the Flask-WTF docs related to CSRF.

Hi Glenn,

I have a

app.config['SECRET KEY'] =

... in my code, and so shouldn't that suffice? I didn't have this error until I added the db function(which work, btw).

Did you try searching for the error message? This StackOverflow post has an answer that includes some helpful tips:

https://stackoverflow.com/questions/21501058/form-validation-fails-due-missing-csrf

Specifically, at the end he says that if you're storing sessions in a non-standard way, things might go wrong... I wonder if the introduction of the db function could have changed the way you store sessions?

There are lots of other good tips in that post too, that might yield results...