如何向appspot提供secret_key

时间:2015-10-12 17:30:06

标签: python google-app-engine

我有一个使用会话的应用程序,在我的框中我输入了一个secret_key来使其工作。当我上传到appspot它崩溃,因为没有设置secret_key。我该如何解决这个问题:

Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "/base/data/home/apps/s~canada-math/1.387800730829010736/login.py", line 30, in dispatch
    self.session_store = sessions.get_store(request=self.request)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2_extras/sessions.py", line 454, in get_store
    store = request.registry[key] = factory(request)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2_extras/sessions.py", line 308, in __init__
    required_keys=('secret_key',))
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1361, in load_config
    self._validate_required(key, config, required_keys)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1375, in _validate_required
    'Missing configuration keys for %r: %r.' % (key, missing))
Exception: Missing configuration keys for 'webapp2_extras.sessions': ['secret_key'].

1 个答案:

答案 0 :(得分:0)

来自https://webapp-improved.appspot.com/api/webapp2_extras/sessions.html#webapp2_extras.sessions.SessionStore

  

配置字典可以传递给__init__()或应用程序   必须使用定义的secret_key配置进行初始化。该   配置是一个简单的字典:

config = {}
config['webapp2_extras.sessions'] = {
    'secret_key': 'my-super-secret-key',
}

app = webapp2.WSGIApplication([
    ('/', HomeHandler),
], config=config)

您需要为my-super-secret-key使用自己的值,并且应该在主wsgi应用中定义它。