[gevent] Getting gevent-websocket to work

514 views
Skip to first unread message

Allard

unread,
Jan 13, 2012, 2:53:07 PM1/13/12
to gevent: coroutine-based Python network library
All, Jeffrey Gelens,

I am trying to get gevent-websocket to work. I cloned the rep,
installed and tried the test.py as well as the code below (taken from
http://www.gelens.org/code/gevent-websocket/):

from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler

def websocket_app(environ, start_response):
# if environ["PATH_INFO"] == '/echo':
if True:
ws = environ["wsgi.websocket"]
message = ws.wait()
ws.send(message)


server = pywsgi.WSGIServer(('127.0.0.1', 8000), websocket_app,
handler_class=WebSocketHandler)
server.serve_forever()

As a client I am using:
http://websocket.org/echo.html

With the location set to:
ws://localhost:8000

When I try to connect, python throws errors like:


python websocket_test.py
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gevent-0.13.6-py2.7-
linux-i686.egg/gevent/pywsgi.py", line 438, in handle_one_response
self.run_application()
File "/usr/local/lib/python2.7/dist-packages/gevent_websocket-0.2.2-
py2.7.egg/geventwebsocket/handler.py", line 36, in run_application
if self.websocket:
AttributeError: 'WebSocketHandler' object has no attribute 'websocket'
<WSGIServer fileno=3 address=127.0.0.1:8000>: Failed to handle
request:
request = GET / HTTP/1.1 from ('127.0.0.1', 51984)
application = <function websocket_app at 0xb72a2e64>

127.0.0.1 - - [2012-01-13 14:50:40] "GET / HTTP/1.1" 000 0 0.000454
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gevent-0.13.6-py2.7-
linux-i686.egg/gevent/greenlet.py", line 390, in run
result = self._run(*self.args, **self.kwargs)
File "/usr/local/lib/python2.7/dist-packages/gevent-0.13.6-py2.7-
linux-i686.egg/gevent/pywsgi.py", line 571, in handle
handler.handle()
File "/usr/local/lib/python2.7/dist-packages/gevent-0.13.6-py2.7-
linux-i686.egg/gevent/pywsgi.py", line 180, in handle
result = self.handle_one_request()
File "/usr/local/lib/python2.7/dist-packages/gevent-0.13.6-py2.7-
linux-i686.egg/gevent/pywsgi.py", line 314, in handle_one_request
self.handle_one_response()
File "/usr/local/lib/python2.7/dist-packages/gevent_websocket-0.2.2-
py2.7.egg/geventwebsocket/handler.py", line 49, in handle_one_response
return super(WebSocketHandler, self).handle_one_response()
File "/usr/local/lib/python2.7/dist-packages/gevent-0.13.6-py2.7-
linux-i686.egg/gevent/pywsgi.py", line 454, in handle_one_response
self.start_response(_INTERNAL_ERROR_STATUS,
_INTERNAL_ERROR_HEADERS)
File "/usr/local/lib/python2.7/dist-packages/gevent_websocket-0.2.2-
py2.7.egg/geventwebsocket/handler.py", line 109, in start_response
if self.websocket_connection:
AttributeError: 'WebSocketHandler' object has no attribute
'websocket_connection'
<Greenlet at 0xb7310becL: <bound method WSGIServer.handle of
<WSGIServer at 0xb72a1facL fileno=3 address=127.0.0.1:8000>>(<socket
at 0xb72a64ccL fileno=[Errno 9] Bad file d, ('127.0.0.1', 51984))>
failed with AttributeError

Does anyone know what I am doing wrong?

Thanks so much for the help!

Allard

Allard

unread,
Jan 23, 2012, 6:43:04 PM1/23/12
to gevent: coroutine-based Python network library
A kind stranger saw this thread and wrote me directly and suggested
using the stable branch. I just ran:
hg update stable
and it all works!

On Jan 13, 2:53 pm, Allard <allard.schip...@gmail.com> wrote:
> All, Jeffrey Gelens,
>
> I am trying to get gevent-websocket to work. I cloned the rep,
> installed and tried the test.py as well as the code below (taken fromhttp://www.gelens.org/code/gevent-websocket/):

Jeffrey Gelens

unread,
Feb 2, 2012, 6:17:53 PM2/2/12
to gevent: coroutine-based Python network library
I just released version 0.3.0 on PyPi. This one should work too.

Regards,

Jeffrey Gelens
Reply all
Reply to author
Forward
0 new messages