我使用以下代码创建了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
答案 0 :(得分: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']