librelist archives

« back to archive

Third party session interfaces or Flask-Login broken?

Third party session interfaces or Flask-Login broken?

From:
Smartboy
Date:
2012-07-20 @ 00:17
Hey everyone,

I'm trying to use Redis to store sessions server-side rather than the
default client-side storage, and was trying to use the snippet on the site
for this. I'm also using Flask-Login for user session management, and use
the Flask test client for running unit tests.

When I add the snippet and the session interface to app.session_interface,
it starts returning errors and crashing the server. The specific error is
below.  I thought this could be a bug with the Redis session snippet, so I
tried dropping the Itsdangerous snippet in instead, and got the same error.
In fact, the only session interface that works is the default interface.
From debugging, it looks like the contents are corrupted between when a
session is created and on_update, and an '_id' with a byte value is added
 Is there a bug, or perhaps something changed and neither of these were
updated?

Traceback (most recent call last):


   File "/home/ccdc/Projects/Cheshire-Engine/tests/test_teams_info.py",
line 130, in test_modify_team_data_no_param


     patch = self.app.patch('/teams/2', data=json.dumps(query_data))


   File

"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/werkzeug/test.py",
line 740, in patch


     return self.open(*args, **kw)


   File

"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/flask/testing.py",
line 102, in open


     follow_redirects=follow_redirects)


   File

"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/werkzeug/test.py",
line 675, in open


     rv = run_wsgi_app(self.application, environ, buffered=buffered)


   File

"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/werkzeug/test.py",
line 818, in run_wsgi_app


     app_iter = app(environ, start_response)


   File
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/flask/app.py",
line 1701, in __call__


     return self.wsgi_app(environ, start_response)


   File
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/flask/app.py",
line 1689, in wsgi_app


     response = self.make_response(self.handle_exception(e))


   File
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/flask/app.py",
line 1687, in wsgi_app


     response = self.full_dispatch_request()


   File
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/flask/app.py",
line 1362, in full_dispatch_request


     response = self.process_response(response)


   File
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/flask/app.py",
line 1566, in process_response


     self.save_session(ctx.session, response)


   File
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/flask/app.py",
line 804, in save_session


     return self.session_interface.save_session(self, session, response)


   File
"/home/ccdc/Projects/Cheshire-Engine/ScoringServer/itsdangerous_session.py",
line 48, in save_session


     val = self.get_serializer(app).dumps(dict(session))


   File

"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/itsdangerous.py",
line 424, in dumps


     return self.make_signer(salt).sign(self.dump_payload(obj))


   File

"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/itsdangerous.py",
line 519, in dump_payload


     json = super(URLSafeSerializerMixin, self).dump_payload(obj)


   File

"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/itsdangerous.py",
line 407, in dump_payload


     return self.serializer.dumps(obj)


   File

"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/itsdangerous.py",
line 539, in dumps


     return simplejson.dumps(obj, separators=(',', ':'))


   File "/usr/lib/python2.7/json/__init__.py", line 238, in dumps


     **kw).encode(obj)


   File "/usr/lib/python2.7/json/encoder.py", line 201, in encode


     chunks = self.iterencode(o, _one_shot=True)


   File "/usr/lib/python2.7/json/encoder.py", line 264, in iterencode


     return _iterencode(o, 0)


 UnicodeDecodeError: 'utf8' codec can't decode byte 0xa7 in position 1:
invalid start byte


Thanks,
Smartboy

Re: Third party session interfaces or Flask-Login broken?

From:
Smartboy
Date:
2012-07-20 @ 00:35
I forgot to put this in here, but my code is available on Github if that
will help with debugging. See
http://github.com/smartboyathome/Cheshire-Engine
On Jul 19, 2012 5:17 PM, "Smartboy" <smartboyathome@gmail.com> wrote:

> Hey everyone,
>
> I'm trying to use Redis to store sessions server-side rather than the
> default client-side storage, and was trying to use the snippet on the site
> for this. I'm also using Flask-Login for user session management, and use
> the Flask test client for running unit tests.
>
> When I add the snippet and the session interface to app.session_interface,
> it starts returning errors and crashing the server. The specific error is
> below.  I thought this could be a bug with the Redis session snippet, so I
> tried dropping the Itsdangerous snippet in instead, and got the same error.
> In fact, the only session interface that works is the default interface.
> From debugging, it looks like the contents are corrupted between when a
> session is created and on_update, and an '_id' with a byte value is added
>  Is there a bug, or perhaps something changed and neither of these were
> updated?
>
> Traceback (most recent call last):
>
>
>    File "/home/ccdc/Projects/Cheshire-Engine/tests/test_teams_info.py",
> line 130, in test_modify_team_data_no_param
>
>
>      patch = self.app.patch('/teams/2', data=json.dumps(query_data))
>
>
>    File
> 
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/werkzeug/test.py",
> line 740, in patch
>
>
>      return self.open(*args, **kw)
>
>
>    File
> 
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/flask/testing.py",
> line 102, in open
>
>
>      follow_redirects=follow_redirects)
>
>
>    File
> 
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/werkzeug/test.py",
> line 675, in open
>
>
>      rv = run_wsgi_app(self.application, environ, buffered=buffered)
>
>
>    File
> 
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/werkzeug/test.py",
> line 818, in run_wsgi_app
>
>
>      app_iter = app(environ, start_response)
>
>
>    File
> 
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/flask/app.py",
> line 1701, in __call__
>
>
>      return self.wsgi_app(environ, start_response)
>
>
>    File
> 
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/flask/app.py",
> line 1689, in wsgi_app
>
>
>      response = self.make_response(self.handle_exception(e))
>
>
>    File
> 
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/flask/app.py",
> line 1687, in wsgi_app
>
>
>      response = self.full_dispatch_request()
>
>
>    File
> 
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/flask/app.py",
> line 1362, in full_dispatch_request
>
>
>      response = self.process_response(response)
>
>
>    File
> 
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/flask/app.py",
> line 1566, in process_response
>
>
>      self.save_session(ctx.session, response)
>
>
>    File
> 
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/flask/app.py",
> line 804, in save_session
>
>
>      return self.session_interface.save_session(self, session, response)
>
>
>    File
> "/home/ccdc/Projects/Cheshire-Engine/ScoringServer/itsdangerous_session.py",
> line 48, in save_session
>
>
>      val = self.get_serializer(app).dumps(dict(session))
>
>
>    File
> 
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/itsdangerous.py",
> line 424, in dumps
>
>
>      return self.make_signer(salt).sign(self.dump_payload(obj))
>
>
>    File
> 
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/itsdangerous.py",
> line 519, in dump_payload
>
>
>      json = super(URLSafeSerializerMixin, self).dump_payload(obj)
>
>
>    File
> 
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/itsdangerous.py",
> line 407, in dump_payload
>
>
>      return self.serializer.dumps(obj)
>
>
>    File
> 
"/home/ccdc/Projects/python-2.7.3/local/lib/python2.7/site-packages/itsdangerous.py",
> line 539, in dumps
>
>
>      return simplejson.dumps(obj, separators=(',', ':'))
>
>
>    File "/usr/lib/python2.7/json/__init__.py", line 238, in dumps
>
>
>      **kw).encode(obj)
>
>
>    File "/usr/lib/python2.7/json/encoder.py", line 201, in encode
>
>
>      chunks = self.iterencode(o, _one_shot=True)
>
>
>    File "/usr/lib/python2.7/json/encoder.py", line 264, in iterencode
>
>
>      return _iterencode(o, 0)
>
>
>  UnicodeDecodeError: 'utf8' codec can't decode byte 0xa7 in position 1:
> invalid start byte
>
>
> Thanks,
> Smartboy
>