-1

wsgi使用以下代码创建了一个服务器。但是当客户端连接到它时,我遇到了一些错误并且连接失败。

代码:

#! /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()

错误:

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
4

1 回答 1

0

__call__()应该返回符合 wsgi 的结果。

请参阅http://www.python.org/dev/peps/pep-0333/ 您可以找到以下代码示例:

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']
于 2014-01-27T05:48:36.707 回答