Python – Flask error when using flash(): TypeError

Flask error when using flash(): TypeError… here is a solution to the problem.

Flask error when using flash(): TypeError

I’m new to Flask and am trying to use it with Google Cloud to build apps. When you add a flash() statement to display an error message to the user, the following error occurs:

TypeError: set_cookie() got an unexpected keyword argument 'samesite'.

I’m not sure how to fix this. I’ve set up secret_key and looked at the example.

Thanks for any help.

Solution

Your browser is sending a cookie with the SameSite cookie attribute, but your app doesn’t support it.

Support for this attribute (the web application library used by Flask) was added in Werkzeug 0.14. You will need to upgrade your dependencies to use this updated version.

If you are using Google App Engine, you can do this by adding the following line to the requirements.txt file:

werkzeug>=0.14

Related Problems and Solutions