python - 是新浪微博的cookies格式不对还是http.cookies的bug?

 刘刚michaelup_340 发布于 2022-10-25 17:04

登录新浪微博时获取到cookies的expiresSaturday, 06-Mar-2027 02:32:46 GMT;这样的格式,但是http.cookies库解析时expires的需要的格式是Sat, 06-Mar-2027 02:32:46 GMT;,使用的正则表达式如下:

_CookiePattern = re.compile(r"""
    \s*                            # Optional whitespace at start of cookie
    (?P                       # Start of group 'key'
    [""" + _LegalKeyChars + r"""]+?   # Any word of at least one letter
    )                              # End of group 'key'
    (                              # Optional group: there may not be a value.
    \s*=\s*                          # Equal Sign
    (?P                         # Start of group 'val'
    "(?:[^\\"]|\\.)*"                  # Any doublequoted string
    |                                  # or
    \w{3},\s[\w\d\s-]{9,11}\s[\d:]{8}\sGMT  # Special case for "expires" attr
    |                                  # or
    [""" + _LegalValueChars + r"""]*      # Any word or empty string
    )                                # End of group 'val'
    )?                             # End of optional value group
    \s*                            # Any number of spaces.
    (\s+|;|$)                      # Ending either at space, semicolon, or EOS.
    """, re.ASCII | re.VERBOSE)    # re.ASCII may be removed if safe.

这个正则表达式解析微博cookies时会在expries处出错,需要把\w{3}改成\w{3,9}才能正确解析微博的cookies。
我想问的是http有对expries规定格式吗?这个bug是属于新浪不按格式还是http.cookies解析不兼容?而使用requests库解析时没有有题。

1 个回答
  • 应该是新浪写的就是 Sat 而浏览器显示会补全

    2022-10-26 23:23 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有