1
BOYPT 2012-11-27 09:23:55 +08:00 1
=.=b
Cookies是浏览器作为Header发给http服务器的。 一般web框架都会带了getCookies方法,一般是request对象的,各个框架都大同小异。(和python一点关系都没有) |
2
Livid MOD Cookie 就是客户端发送的请求中 Set-Cookie: 后面的那一行,用 urlencode 方式编码的一个字典。
|
3
tsuibin 2012-11-27 10:33:11 +08:00 1
import Cookie
cookie = Cookie.SimpleCookie() cookie["uname"]= "demo" cookie["pwd"] = "demo" print "Content-type: text/plain" print cookie.output() |
4
killpanda OP |
7
Livid MOD |
8
tsuibin 2012-11-28 10:12:39 +08:00 1
取数据
import Cookie import os print "Content-type: text/plain\n" try: cookie = Cookie.SimpleCookie(os.environ["HTTP_COOKIE"]) print "name= " + cookie["name"].value print "pwd= " + cookie["pwd"].value except (Cookie.CookieError, KeyError): print "cookie not set!" |