Python gevent-socketio server error on client connection

588 views Asked by At

I've created a wsgi server using the following code. But when a client connects to it I am getting some errors and the connection fails.

code:

#! /usr/bin/env python

import gevent.monkey
gevent.monkey.patch_all()

from socketio.server import SocketIOServer

class Application(object):
    def __init__(self):
        print "Hiii"

    def __call__(self, environ, start_response):
        print "Hello"

def main():
    server = SocketIOServer(('127.0.0.1',1234), Application(), namespace = "", policy_server=False)
    server.serve_forever()

if __name__ ==  '__main__':
    main()

Error:

Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/gevent/pywsgi.py", line 449, in handle_one_response
    self.run_application()
  File "/usr/lib/pymodules/python2.7/gevent/pywsgi.py", line 436, in run_application
    self.process_result()
  File "/usr/lib/pymodules/python2.7/gevent/pywsgi.py", line 425, in process_result
    for data in self.result:
TypeError: 'NoneType' object is not iterable
1

There are 1 answers

0
Keewon Seo On BEST ANSWER

Your __call__() should return wsgi-compliant result.

See http://www.python.org/dev/peps/pep-0333/ You can find following code sample:

def simple_app(environ, start_response):
    """Simplest possible application object"""
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain')]
    start_response(status, response_headers)
    return ['Hello world!\n']