cooks['username''bobcooks['username']['path''/myscriptcooks['visited'value 'tue jun : : print(cooks['visited']set-cookievisited="tue jun : : print(cooksset-cookieusername=bobpath=/myscript set-cookievisited="tue jun : : receiving cookie nowwhen the client visits the page again in the futurethe cookie' data is sent back from the browser to the server in http headers againin the form "cookiename =value name =value for examplecookievisited= roughlythe browser client returns all cookies that match the requested server' domain name and path in the cgi script on the serverthe environment variable http_cookie contains the raw cookie data headers string uploaded from the clientit can be extracted in python as followsimport oshttp cookies cooks http cookies simplecookie(os environ get("http_cookie")vcook cooks get("visited" morsel dictionary if vcook !nonetime vcook value herethe simplecookie constructor call automatically parses the passed-in cookie data string into dictionary of morsel objectsas usualthe dictionary get method returns default none if key is absentand we use the morsel object' value attribute to extract the cookie' value string if sent using cookies in cgi scripts to help put these pieces togetherexample - lists cgi script that stores clientside cookie when first visited and receives and displays it on subsequent visits example - pp \internet\web\cgi-bin\cookies py ""create or use client-side cookie storing usernamethere is no input form data to parse in this example ""import http cookiesos cookstr os environ get("http_cookie"cookies http cookies simplecookie(cookstrusercook cookies get("user"fetch if sent if usercook =nonecreate first time saving state information in cgi scripts