pallets-eco / flask-session

Server side session extension for Flask
https://flask-session.readthedocs.io
BSD 3-Clause "New" or "Revised" License
507 stars 238 forks source link

this is probably something dumb on my end but.... #42

Closed SkyLeach closed 8 years ago

SkyLeach commented 8 years ago

my entire app (from docs):

#!/usr/bin/env python
from flask import Flask, session
from flask.ext.session import Session
from flask import current_app
import pprint

app = Flask(__name__)
# Check Configuration section for more details
#SESSION_TYPE = 'redis'
app.config.from_object('cvms_flask.config')
Session(app)

@app.route('/set/')
def set():
    pprint.pprint(current_app.config)
    session['key'] = 'value'
    return 'ok'

@app.route('/get/')
def get():
    return session.get('key', 'not set')

if __name__ == '__main__':
    app.run()

exception:

Traceback (most recent call last):
  File "/Users/magregor/.virtualenvs/cvms/lib/python3.5/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/magregor/.virtualenvs/cvms/lib/python3.5/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Users/magregor/.virtualenvs/cvms/lib/python3.5/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/magregor/.virtualenvs/cvms/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/magregor/.virtualenvs/cvms/lib/python3.5/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/magregor/.virtualenvs/cvms/lib/python3.5/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/magregor/.virtualenvs/cvms/lib/python3.5/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/magregor/.virtualenvs/cvms/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/Users/magregor/.virtualenvs/cvms/lib/python3.5/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/magregor/.virtualenvs/cvms/lib/python3.5/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/magregor/src/cisco/cvms/tests/testsession.py", line 16, in set
    session['key'] = 'value'
  File "/Users/magregor/.virtualenvs/cvms/lib/python3.5/site-packages/werkzeug/local.py", line 341, in __setitem__
    self._get_current_object()[key] = value
  File "/Users/magregor/.virtualenvs/cvms/lib/python3.5/site-packages/flask/sessions.py", line 126, in _fail
    raise RuntimeError('the session is unavailable because no secret '
RuntimeError: the session is unavailable because no secret key was set.  Set the secret_key on the application to something unique and secret.

however dumping current_app.config (right before attempting to use the session):

{ #snip
 'RULES_LOGLEVEL': 'DEBUG',
 'SECRET_KEY': '505<hash-snipped/>',
 'SEND_FILE_MAX_AGE_DEFAULT': 43200,
 'SERVER_NAME': None,
#snip }
SkyLeach commented 8 years ago

well it's not in the docs and the exception is misleading at best but apparently thereis no default session handler and that caused the exception. When I selected filesystem and commented out all of the config options set to their Null defaults everything worked.