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

后端 未结 1 2053
心在旅途
心在旅途 2020-12-19 12:09

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条回答
  • 2020-12-19 12:38

    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')
    
    0 讨论(0)
提交回复
热议问题