heroku-python / flask-sockets

[DEPRECATED] Alternative: https://github.com/miguelgrinberg/flask-sock
MIT License
1.74k stars 164 forks source link

AttributeError: 'WebSocket' object has no attribute 'socket' #24

Closed no13bus closed 8 years ago

no13bus commented 9 years ago

my flask version is 0.10. When I type gunicorn -k flask_sockets.worker chat:app, there is an error: AttributeError: 'WebSocket' object has no attribute 'socket' why?

syntonym commented 9 years ago

@no13bus Can you show the code that throws that error?

jcipriano commented 9 years ago

I just ran into this as well.

This code is from: https://github.com/heroku-examples/python-websockets-chat/blob/master/chat.py

@sockets.route('/receive')
def outbox(ws):
    """Sends outgoing chat messages, via `ChatBackend`."""
    chats.register(ws)

    while ws.socket is not None:
        # Context switch while `ChatBackend.start` is running in the background.
        gevent.sleep()
jcipriano commented 9 years ago

The issue does not occur if you downgrade gevent-websocket to version 0.3.6 as discussed here:

https://bitbucket.org/Jeffrey/gevent-websocket/issue/50/errors-with-version-092-and-flask-sockets

However, the last solution provided in that discussion to work with the recent version of gevent-websocket did not work for me.

Hope this helps someone.

syntonym commented 9 years ago

It looks like the websocket api changed. An websocket object has no longer a socket attribute, but a boolean closed that should indicate if the websocket is open or not.

@jcipriano What happens if you use the solution with while not ws.closed:?

EDIT: Changed with not ws.closed to while not ws.closed

versae commented 9 years ago

Thanks @syntonym, that worked for me.

ondrae commented 8 years ago

@syntonym while not ws.closed:

syntonym commented 8 years ago

@ondrae You are of course correct. Thanks! BTW: This issue can probably be closed?

kennethreitz commented 8 years ago

while not ws.closed is indeed proper. I've updated the code in the example chat app repository to feature the new usage. Sorry for the confusion!