[issue41945] http.cookies.SimpleCookie.parse error after [keys] or some JSON data values

Jan Novak report at bugs.python.org
Tue Jan 4 11:01:46 EST 2022


Jan Novak <xnovakj at seznam.cz> added the comment:

New examples with the structured data.

Problems are with quotes and spaces inside { or [

cookie-script.com set those cookie data:
CookieScriptConsent={"action":"accept","categories":"[\\"performance\\"]"}

Python loads only cookies before that JSON structure

>>> from http.cookies import SimpleCookie
>>> ck = SimpleCookie()
>>> ck.load('id=12345; CookieScriptConsent={"action":"accept","categories":"[\\"performance\\"]"}; something="not loaded"')
>>> print(ck)
Set-Cookie: id=12345

This works:
>>> ck.load('id=12345; complex_data={1:[1,2]}; something="loaded"')
>>> print(ck)
Set-Cookie: complex_data={1:[1,2]}
Set-Cookie: id=12345
Set-Cookie: something="loaded"

This not works:
>>> ck.load('id=12345; complex_data={1:[1, 2]}; something="not loaded"')
>>> print(ck)
Set-Cookie: complex_data={1:[1,
Set-Cookie: id=12345

Conclusion:
Parsing JSON like cookie objects works, except quotes and without spaces. 

Exist some new RFC with JSON data support?
How implementation/support/solution in diferent languages?
Exist another Python library which support cookie with JSON data?

----------
title: http.cookies.SimpleCookie.parse error after [keys] -> http.cookies.SimpleCookie.parse error after [keys] or some JSON data values
versions: +Python 3.10 -Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41945>
_______________________________________


More information about the Python-bugs-list mailing list