http cookies (cookiethe http cookies module provides server-side support for working with http cookies in python the module is called cookie cookies are used to provide state management in servers that implement sessionsuser loginsand related features to drop cookie on user' browseran http server typically adds an http header similar to the following to an http responseset-cookiesession= expires=sun -feb- : : gmtpath=/domain=foo bar com alternativelya cookie can be set by embedding javascript in the section of an html documentdocument cookie "session= expires=sun -feb- : : gmtfeb path=/domain=foo bar com;the http cookies module simplifies the task of generating cookie values by providing special dictionary-like object which stores and manages collections of cookie values known as morsels each morsel has namea valueand set of optional attributes containing metadata to be supplied to the browser {expirespathcommentdomainmax-agesecureversionhttponlythe name is usually simple identifier such as "nameand must not be the same as one of the metadata names such as "expiresor "paththe value is usually short string to create cookiesimply create cookie object like thisc simplecookie(nextcookie values (morselscan be set using ordinary dictionary assignmentc["session" ["user""beazleyadditional attributes of specific morsel are set as followsc["session"]["path""/ ["session"]["domain""foo bar comc["session"]["expires"" -feb- : : gmtto create output representing the cookie data as set of http headersuse the output(method for exampleprint( output()produces two lines of output set-cookiesession= expirespath=/domainset-cookieuser=beazley when browser sends cookie back to an http serverit is encoded as string of key=value pairssuch as "session= user=beazleyoptional attributes such as expirespathand domain are not returned the cookie string can usually be found in the http_cookie environment variablewhich can be read by cgi applications to recover cookie valuesuse code similar to the followingc simplecookie(os environ["http_cookie"]session ["session"value user ["user"value the following documentation describes the simplecookie object in more detail lib fl ff