1

I have a Python project built using the Flask framework.

The project is established and I have installed and ran it on numerous machines (Ubuntu and OSX) using virtualenv.

I went to set up my project on a new computer with Yosemite installed. It installed all of the requirements with no errors and the site runs locally without errors.

The problem is that the Flask session is always an empty dict (nothing is ever in the session).

7
  • ...and you're sure you're creating sessions to begin with? Commented Jan 6, 2015 at 22:13
  • Yes, I'm sure sessions are being created and the exact same code base is working on other environments. Commented Jan 6, 2015 at 22:18
  • Okay. Since I don't have the code to try it on my box (Xubuntu, no OSX sorry!), I can't really say one way or another. What do you do to verify that sessions are present in the other environments? What other setup is on those boxes that may not be on the OSX box? Commented Jan 6, 2015 at 22:19
  • The other environments definitely have sessions as data persists between requests. Session data such as login functionality works on all of the other environments but not on the problem machine. I also logged the session's data to the console and printed it out in the browser to verify this. For the environments it works, I see "{'foo': 'bar',...}" but for the problem environment I see "{}". BTW, I really appreciate your help! Commented Jan 6, 2015 at 22:27
  • Rule out anything that may be different between the virtualenvs; different Python versions may be causing this. I do want to help, but there's very little I can go off of; I'm simply grasping at straws here. Commented Jan 6, 2015 at 22:31

2 Answers 2

2

Note to self: make sure memcached is running.

Sign up to request clarification or add additional context in comments.

Comments

1

Create a new route with the following code in the view function:

if 'logged' in session:
    return True
return False

Then you can add a unit test:

def test_no_session(self):
   response = self.app.get('/test')
   self.assertEqual(False, response.data)

def test_session(self):
    with self.app:
        with self.app.session_transaction() as session:
            session['logged'] = True
        response = self.app.get('/test')
    self.assertEqual(True, response.data)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.