python - Removing Flask session -


in app after logging in, set:

session['venue_id'] = true 

in javascript connect websocket:

var socket = io.connect('http://my.ip.address.' + ':' + '80' + namespace);   

this triggers following code on server:

@socketio.on('connect', namespace='/test') def test_connect():     if session.get('venue_id'):        session.pop('venue_id', none)     else:         request.namespace.disconnect()   

following make calls api check:

if session.get('venue_id') 

however, goes through fine. have thought these requests not have gone through if statement venue_id had been popped?

i read answer here: python + flask - removing key session fast

but confused purpose of session.pop('venue_id', none) is?

any clearing appreciated.

you need send (non-websocket) response alter session. popping value nothing, browser doesn't update it's side , sends data again next request. right now, application:

  1. logs in, sets value, returns response
  2. sends request (for websocket), sends value
    1. whatever response socket sends occurs before test_connect event handler, doesn't pop value
    2. event handler runs, no way tell browswer session has changed
  3. browser sends request other page, sends value

probably simplest solution store session server side, can alter without sending response.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -