import http.cookies cookie = http.cookies.SimpleCookie() cookie["username"] = "johndoe" cookie["username"]["expires"] = 3600 # seconds print(cookie)
import http.cookies from http.server import BaseHTTPRequestHandler class MyHandler(BaseHTTPRequestHandler): def do_GET(self): cookies = http.cookies.SimpleCookie(self.headers.get('Cookie')) if "username" in cookies: print("Hello, " + cookies["username"].value) else: print("No username cookie found")This code defines a custom HTTP request handler that reads the "Cookie" header from an incoming HTTP request and parses it into a `SimpleCookie` object. It then checks if a cookie named "username" was sent in the request and prints a message accordingly. So, we can conclude that these examples are using the built-in `http.cookies` package library in Python.