Discussion:
[bottlepy] CORS not working properly with Beaker-based sessions
Andres L.
2015-11-16 00:37:02 UTC
Permalink
Hi.
I'm using CORS with bottle.py. I'm using this in this way:

def enable_cors(fn):
def _enable_cors(*args, **kwargs):
# set CORS headers
#bottle.response.content_type = 'application/json'
bottle.response.headers['Access-Control-Allow-Origin'] = '*'
bottle.response.headers['Access-Control-Allow-Methods'] = 'GET, POST,
PUT, OPTIONS'
bottle.response.headers['Access-Control-Allow-Headers'] = 'Origin,
Accept, Content-Type, X-Requested-With, X-CSRF-Token'

if bottle.request.method != 'OPTIONS':
# actual request; reply with the actual response
return fn(*args, **kwargs)

return _enable_cors

Then I use this in this way, for each new function:

bottle.route( '/netout', method=['OPTIONS', 'POST'] )
@enable_cors
def example ):
sesion = bottle.request.environ.get( 'beaker.session' )
sesion['data'] = 'user'
sesion.save( )
return {}

But when I collect this

try:
if ( sesion['netin'] != '' ):
loggedIn = True
except KeyError:
# no session

It's like the session never existed before. What am I doing wrong?

Thank you in advance.

Andres
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...