gpt4 book ai didi

Python - 将 set-cookies 响应转换为 cookies 字典

转载 作者:太空宇宙 更新时间:2023-11-03 15:15:21 29 4
gpt4 key购买 nike

如何从 httplib2 响应中转换 response['set-cookie'] 输出字符串

"cookie1=xxxyyyzzz;Path=/;Expires=Wed, 03-Feb-2015 08:03:12 GMT;Secure;HttpOnly, cookie2=abcdef;Path=/;Secure"

{'cookie1':'xxxyyyzzz','cookies2':'abcdef'}

最佳答案

使用http.cookies :

>>> c = "cookie1=xxxyyyzzz;Path=/;Expires=Wed, 03-Feb-2015 08:03:12 GMT;Secure;HttpOnly, cookie2=abcdef;Path=/;Secure"
>>> from http.cookies import SimpleCookie
>>> cookie = SimpleCookie()
>>> cookie.load(c)
>>> cookie
<SimpleCookie: cookie1='xxxyyyzzz' cookie2='abcdef'>
>>> {key: value.value for key, value in cookie.items()}
{'cookie1': 'xxxyyyzzz', 'cookie2': 'abcdef'}

关于Python - 将 set-cookies 响应转换为 cookies 字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21522586/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com