Sunday 26 February 2017

Websocket with python Bottle + uwsgi | env vars

I actually try to set up a bottle python application based on uwsgi. I need uwsgi for websocket support.




My really basic code looks like that:
(webserver.py)



from bottle import route, run, static_file, error, template
import uwsgi
import bottle
from bottle import route, template

app = application = bottle.default_app()


@route('/')
def index():
uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'], env('HTTP_ORIGIN', ''))
while True:
msg = uwsgi.websocket_recv()
uwsgi.websocket_send(msg)
return template('inputs', name='inputs')

@route('/static/')
def server_static(filepath):

return static_file(filepath, root='./static/')


I just start this file by:



uwsgi --http-socket :80 --http-websockets --wsgi-file webserver.py


My error message looks like that:




...
uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'], env('HTTP_ORIGIN', ''))
NameError: global name 'env' is not defined
...


The websocket handshakes needs the env vars but I got no idea what it is and how to implement them to my code.



EDIT: I already tried to import env by




from uwsgi import env 


but it doesn't solve the proble.

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...