
form=cgi.FieldStorage() cookie=Cookie.SimpleCookie(os.environ["HTTP_COOKIE"]) def get_param(param,default): global cookie if form.getvalue(param) is not None: return form.getvalue(param) # get KB from form cookie[param]=form.getvalue(param)# save KB to cookie elif cookie[param].value is not None: return cookie[param].value else: return default # default kb=get_param("kb","1111") print "Content-Type: text/html; charset=utf-8" print cookie print "" print kb
Ошибка:
Traceback (most recent call last):
File "index.py", line 15, in <module>
cookie=Cookie.SimpleCookie(os.environ["HTTP_COOKIE"])
File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'HTTP_COOKIE'
Как правильно выкрутиться?