How do I set the `SameSite` attribute of HTTP cookies in python?

ぃ、小莉子 提交于 2020-01-06 03:50:08

问题


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.


回答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')


来源:https://stackoverflow.com/questions/50813091/how-do-i-set-the-samesite-attribute-of-http-cookies-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!