V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
zhubapi
V2EX  ›  Python

SAE本地调试调用set_secure_cookie是报错

  •  
  •   zhubapi · 2013-04-21 20:32:19 +08:00 · 3851 次点击
    这是一个创建于 4234 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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='
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2803 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 14:23 · PVG 22:23 · LAX 06:23 · JFK 09:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.