urllib2 响应中的多个 Set-Cookie 标头
我正在使用 urllib2 与发送回多个 Set-Cookie 标头的网站进行交互。然而,响应头字典仅包含一个 - 似乎重复的键相互覆盖。
有没有办法使用 urllib2 访问重复的标头?
I am using urllib2 to interact with a website that sends back multiple Set-Cookie headers. However the response header dictionary only contains one - seems the duplicate keys are overriding each other.
Is there a way to access duplicate headers with urllib2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 urllib2 docs,结果的
.headers
属性URL 对象是一个httplib.HTTPMessage
(它似乎没有记录,至少在 Python 文档中)。然而,
因此,如果您访问 u.headers['Set-Cookie'],您应该得到一个 Set-Cookie 标头,其中的值以逗号分隔。
确实,情况似乎确实如此。
According to urllib2 docs, the
.headers
attribute of the result URL object is anhttplib.HTTPMessage
(which appears to be undocumented, at least in the Python docs).However,
So, if you access u.headers['Set-Cookie'], you should get one Set-Cookie header with the values separated by commas.
Indeed, this appears to be the case.
但
set-cookie
是不同的。来自 RFC 6265:从理论上讲,这看起来像是一个错误。
set-cookie
is different though. From RFC 6265:In theory then, this looks like a bug.
对我来说绝对不是这样。我在浏览器开发工具中运行了
Python 3.10.0
,OCS 提供了这两个 Set-Cookie 标头:在
r.headers['Set-Cookie']
中,它们是 <强>不合并。仅列出第一个 cookie。This is definitely not the case for me. I ran
Python 3.10.0
in the browser dev tools the OCS provides these two Set-Cookie headers:In the
r.headers['Set-Cookie']
they are NOT combined. Only the first cookie is listed.