SAE本地调试调用set_secure_cookie是报错

2013-04-21 20:32:19 +08:00
 zhubapi
index.wsgi代码如下:
import sae
import tornado.wsgi

from blog import urls as blogurls
from admin import urls as adminurls

settings = {
'debug': True,
}

app = tornado.wsgi.WSGIApplication(blogurls + adminurls, **settings)

application = sae.create_wsgi_app(app)

通过 URL 被调用的方法如下:
class GetCaptcha(BaseHandler):
def get(self):
text = generate_random(4)
# self.set_secure_cookie("captcha", text)
self.set_cookie("captcha", text)

strIO = Recaptcha(text)

# ,mimetype='image/png'
self.set_header("Content-Type", "image/png")
self.write(strIO.read())
return

使用set_cookie没有问题,但是当使用 set_secure_cookie 时报错如下:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tornado-2.1.1-py2.7.egg/tornado/web.py", line 954, in _execute
getattr(self, self.request.method.lower())(*args, **kwargs)
File "/home/dreambt/PycharmProjects/cms4p/5/admin.py", line 485, in get
self.set_secure_cookie("captcha", text)
File "/usr/local/lib/python2.7/dist-packages/tornado-2.1.1-py2.7.egg/tornado/web.py", line 388, in set_secure_cookie
self.set_cookie(name, self.create_signed_value(name, value),
File "/usr/local/lib/python2.7/dist-packages/tornado-2.1.1-py2.7.egg/tornado/web.py", line 398, in create_signed_value
self.require_setting("cookie_secret", "secure cookies")
File "/usr/local/lib/python2.7/dist-packages/tornado-2.1.1-py2.7.egg/tornado/web.py", line 910, in require_setting
"application to use %s" % (name, feature))
Exception: You must define the 'cookie_secret' setting in your application to use secure cookies

setting.py中已经设置了:
COOKIE_SECRET = 'L8LwECiNRxq2N0N2eGxx9MZlrpmuMEimlydNX/vt1LM='
3855 次点击
所在节点    Python
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/66522

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX