【发布时间】:2014-02-18 04:08:48
【问题描述】:
我的最终目标是使用 python 实现一个 WebSocket 服务器。
我通过在我的 python 脚本中导入 tornado 来实现这一点。我还在 apache 中安装了 mod_wsgi,their script 输出 Hello World!,所以 WSGI 似乎工作正常。据我所知,Tornado 也运行良好。
当我使用tornado's wsgi "Hello, world" script时出现问题:
import tornado.web
import tornado.wsgi
import wsgiref.simple_server
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
if __name__ == "__main__":
application = tornado.wsgi.WSGIApplication([
(r"/", MainHandler),
])
server = wsgiref.simple_server.make_server('', 8888, application)
server.serve_forever()
首先,我收到 500 错误,日志告诉我 WSGI 找不到“应用程序”。
所以我删除if __name__ == "__main__",页面无限加载。
我认为这是因为 server.serve_forever(),所以我将其删除以尝试查看 Hello, world
但现在我只收到404: Not Found。这不是我的 apache 404 页面,我知道服务器可以找到我的主 .wsgi 文件...
【问题讨论】:
标签: python websocket tornado mod-wsgi