こちらと同じことを、Python3 で行いました。
jquery-cookie の使い方
Perl: クッキーの使い方
PHP: クッキーの使い方
クッキーを送る
cookie_put.py
#! /usr/bin/python
#
# cookie_put.py
#
# Apr/27/2021
# ------------------------------------------------------------------
from http import cookies
C = cookies.SimpleCookie()
C["message"] = "This is a Test by Python."
C["aa"] = "富士山 by Python"
C["bb"] = "谷川岳 by Python"
C["cc"] = "阿蘇山 by Python"
print(C.output())
print("Content-Type: text/html")
print("")
print("<!DOCTYPE html>")
print("<html lang=\"ja\">")
print("<body>")
print("<p>*** cookie_put.py ***</p>")
print("<p>Apr/27/2021</p>")
print("</body>")
print("</html>")
# ------------------------------------------------------------------
クッキーを確認
cookie_get.py
#! /usr/bin/python
#
# cookie_get.py
#
# Apr/27/2021
# ------------------------------------------------------------------
import os
from http import cookies
cookie = cookies.SimpleCookie()
cookie.load(os.environ["HTTP_COOKIE"])
print("Content-Type: text/html")
print("")
print("<!DOCTYPE html>")
print("<html lang=\"ja\">")
print("<head>")
print("<meta http-equiv=\"CONTENT-TYPE\" content=\"text/html; charset=utf-8\" />")
print("</head>")
print("<body>")
print("<p>*** cookie_get.py *** start ***</p>")
print("message: " + cookie["message"].value + "<br />")
print("aa: " + cookie["aa"].value + "<br />")
print("bb: " + cookie["bb"].value + "<br />")
print("cc: " + cookie["cc"].value + "<br />")
#
# print(session.cookies.get_dict())
print("<p>*** cookie_get.py *** end ***</p>")
print("<p>Apr/27/2021</p>")
print("</body>")
print("</html>")
# ------------------------------------------------------------------