Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

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

Closed
no13bus opened this issue Jan 6, 2015 · 8 comments
Closed

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

no13bus opened this issue Jan 6, 2015 · 8 comments

Comments

@no13bus
Copy link

no13bus commented Jan 6, 2015

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
Copy link

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

@jcipriano
Copy link

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
Copy link

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
Copy link

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
Copy link

versae commented Jun 10, 2015

Thanks @syntonym, that worked for me.

@ondrae
Copy link

ondrae commented Oct 25, 2015

@syntonym while not ws.closed:

@syntonym
Copy link

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

@kennethreitz
Copy link
Contributor

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

6 participants