aiohttp 使用 Google 身份服务后返回空 cookie

问题描述 投票:0回答:1

我将 Google 登录 JavaScript 平台库迁移到 Google Identity Services。在 Safari macOS 中成功登录后,我的

aiohttp
服务器会设置服务器使用的 cookie
myid=10
。不幸的是,当我读取 cookie
request.cookie.get('myid')
时,它返回
None
。问题是谷歌添加了cookie
g_state={"i_l":0}
。 Aiohttp 使用
http.cookies.SimpleCookie
处理
Cookie
标头,当
g_state
出现在
Cookie
标头中的 cookie 之前时,我得到
None
。我创建了一个简单的脚本来重现该问题:

from http.cookies import SimpleCookie
cookie = 'g_state={"i_l":0}; myid=10'  # prints empty
cookie = 'myid=10; g_state={"i_l":0}'  # prints Set-Cookie: myid=10
print(SimpleCookie(cookie))

我尝试了Python 3.6和3.10。他们打印相同的结果。至于解决方法,我从

myid
读取了
request.headers['Cookie']
并且服务器工作了。但正确的解决方法是什么?是 Google 的 cookie 值无效还是 SimpleCookie 无法处理有效的 cookie 或 aiohttp 错误?

python google-apps-script cookies aiohttp
1个回答
0
投票

这不是

aiohttp
问题,而是格式错误的 cookie 和
SimpleCookie

中的错误

https://github.com/python/cpython/issues/92936

© www.soinside.com 2019 - 2024. All rights reserved.