cherrypy and WSGI, problem with mod_wsgi

63 views
Skip to first unread message

Antonio Ragagnin

unread,
Sep 15, 2014, 9:06:58 AM9/15/14
to ws...@googlegroups.com
Hi, I am running a server on OpenShift. I run it with cherrypy embedded in a WSGI environment. My application has some websockets too.

This is how, I initialized the WSGI application object:


class Root(object):
    
def index(self):  return 'I work!'
    
def ws(self):  print('ws request handler: ', cherrypy.request.ws_handler)

cherrypy
.config.update({'environment': 'embedded'}) 
if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0:
    cherrypy
.engine.start(blocking=False)
    atexit
.register(cherrypy.engine.stop)

WebSocketPlugin(cherrypy.engine).subscribe()
cherrypy
.tools.websocket = WebSocketTool()  
conf
['/ws']={'tools.websocket.on': True, 'tools.websocket.handler_cls': MyWebSocketClient}

application 
= cherrypy.Application(Root(), script_name='', config=conf)


Everything works fine, but when I try to connect to the websocket, from browser, I get:

     cherrypy/_cplogging.py, 214, HTTP Traceback (most recent call last):
       
File "cherrypy/_cprequest.py", line 661, in respond
         
self.hooks.run('before_request_body')
       
File "cherrypy/_cprequest.py", line 114, in run
         
raise exc
       
File "cherrypy/_cprequest.py", line 104, in run
         hook
()
       
File "cherrypy/_cprequest.py", line 63, in __call__
         
return self.callback(**self.kwargs)
       
File "ws4py/server/cherrypyserver.py", line 200, in upgrade
         ws_conn
= get_connection(request.rfile.rfile)
   
AttributeError: 'mod_wsgi.Input' object has no attribute 'rfile'



Any idea? should I put something more, so the websocket can work under a WSGI-zed cherrypy?

thanks!

PS: I deleted my recent post since I realized I put a wrong stacktrace, this is the right one!

Antonio Ragagnin

unread,
Sep 15, 2014, 10:29:00 AM9/15/14
to ws...@googlegroups.com
PPS: here I put the code of a minimal WSGI application http://stackoverflow.com/questions/25845161/ws4py-under-cherrypy-under-wsgi-exception-attributeerror-mod-wsgi-input-obje

PPPS: this is a OpenShift application: https://github.com/spocchio/wsgi-cherrypy-ws4py maybe in case anyone is familiar with it, can directly try my code.

Sylvain Hellegouarch

unread,
Sep 15, 2014, 12:40:57 PM9/15/14
to ws...@googlegroups.com
Hi there,



2014-09-15 16:29 GMT+02:00 Antonio Ragagnin <spoc...@gmail.com>:
PPS: here I put the code of a minimal WSGI application http://stackoverflow.com/questions/25845161/ws4py-under-cherrypy-under-wsgi-exception-attributeerror-mod-wsgi-input-obje

PPPS: this is a OpenShift application: https://github.com/spocchio/wsgi-cherrypy-ws4py maybe in case anyone is familiar with it, can directly try my code.



It's hard to tell but since I've never tried with mod_wsgi, I'm not surprised this may failed. Basically, we need to determine how to access the raw socket from the mod_wsgi interface. I'm not really sure it would work anyway as i'm not sure mod_wsgi won't force the socket closing anyhow.

I don't think it's a CherryPy bug so it's unfortunate you created an issue on their tracker.

--
- Sylvain
http://twitter.com/lawouach
Reply all
Reply to author
Forward
0 new messages