0

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/<filepath:path>')
    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.

Borsty
  • 51
  • 4
  • You have no import of env, it's not a built-in function; where did you think it was coming from? – jonrsharpe Nov 25 '17 at 21:36
  • Well if I import the uwsgi env by "from envparse import env" I get the following error message: no python application found, check your startup logs for errors. – Borsty Nov 25 '17 at 21:42

0 Answers0