Skip to content Skip to sidebar Skip to footer

How Do I Set The `samesite` Attribute Of Http Cookies In Python?

Support for Same-Site cookies has landed in Firefox 60, but as of Python 3.6 the standard library cookie module doesn't support the SameSite attribute.

Solution 1:

Support for the SameSite attribute was added on April 7, 2018 in Pull Request #6413.

It's possible to monkey-patch older versions to support the attribute:

try:
    from http.cookies import Morsel
except ImportError:
    from Cookie import Morsel

Morsel._reserved[str('samesite')] = str('SameSite')

Or using six:

from six.moves.http_cookies import Morsel

Morsel._reserved[str('samesite')] = str('SameSite')

Post a Comment for "How Do I Set The `samesite` Attribute Of Http Cookies In Python?"