Possibility and Probability

Coding Python and making businesses…

18 August 2015

Keep Flask from sending too many cookies

by admin

In the Python Flask web framework you can run into an issue where after logging in two cookies are sent back in the HTTP headers. One is the normal “session” cookie, and the other one is called “remember_token”. This can cause a problem with some Android libraries that only expect 1 cookie to be sent back. The cause of this 2nd cookie is because of the flask-login library. It has a “helpful” feature that will send this second cookie. The tricky part is that you can’t really stop it from doing this by manipulating the make_response response object. Instead, when you call login_user you have to pass a 2nd parameter to disable the remember cookie:   This will prevent that “remember_token” cookie from being tacked onto your request headers. The end result is one cookie and the Android Volley library is able to get the correct cookie.

tags: