python SimpleCookie 区分错误

发布于 2024-12-23 16:46:34 字数 415 浏览 4 评论 0原文

当我使用 python SimpleCookie 对象从 http 标头中获取 cookie 时,出现一些异常:

cookiestr = "a_em=[BU]co|12345678-901234567[DG]; Expires=Sat, 31 Dec 2016 17:09:50 GMT; Domain=.somesite.com; Path=/"
C = Cookie.SimpleCookie()
C.load(cookiestr)
print C

输出为:

Set-Cookie: a_em=; Domain=.somesite.com; expires=Sat,; Path=/

cookie 值和 cookie 过期时间错误!

我应该如何解决这个问题?

When i use python SimpleCookie object to pick up cookie from http headers, some exception occurs:

cookiestr = "a_em=[BU]co|12345678-901234567[DG]; Expires=Sat, 31 Dec 2016 17:09:50 GMT; Domain=.somesite.com; Path=/"
C = Cookie.SimpleCookie()
C.load(cookiestr)
print C

the output is:

Set-Cookie: a_em=; Domain=.somesite.com; expires=Sat,; Path=/

the cookie value and the cookie expires time is error!

how should i solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽袖吟 2024-12-30 16:46:34

过期的 RFC 格式应为:

Expires=Sat, 31-Dec-2016 17:09:50 GMT

完整字符串应为(注意引号)

cookiestr = 'a_em="[BU]co|12345678-901234567[DG]"; Expires=Sat, 31-Dec-2016 17:09:50 GMT; Domain=.somesite.com; Path=/'

RFC format for expires should be:

Expires=Sat, 31-Dec-2016 17:09:50 GMT

The full string should be (note quotes)

cookiestr = 'a_em="[BU]co|12345678-901234567[DG]"; Expires=Sat, 31-Dec-2016 17:09:50 GMT; Domain=.somesite.com; Path=/'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文