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='