Question

I am in the process of setting up a python websocket app, the basic code that I have right now is this

import uwsgi

def application(env, start_response):
    # complete the handshake
    uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'], env.get('HTTP_ORIGIN', ''))
    while True:
        msg = uwsgi.websocket_recv()
        uwsgi.websocket_send("Oh!  " + msg)

I run this code using

uwsgi --http :8080 --http-websockets --wsgi-file server.py

The code works correctly and when I use the browser to hit this server I get the expected response. But even though the browser displays the correct response, there is an error in the server logs as follows

Traceback (most recent call last):
  File "pingserver.py", line 9, in application
    msg = uwsgi.websocket_recv()
IOError: unable to receive websocket message

Any ideas on how to fix this error? What am I doing wrong here?

Was it helpful?

Solution

you should get that error only when the client (the browser) brutally closes the websocket connection. You can trap it and return from the callable without problems

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top