我正试图从龙卷风websockets文档中获取hello-world示例。我对龙卷风很新,对websockets也很陌生。我直接从文档中指定了以下处理程序:
class EchoWebSocket(tornado.websocket.WebSocketHandler):
def open(self):
print "WebSocket opened"
def on_message(self, message):
self.write_message(u"You said: " + message)
def on_close(self):
print "WebSocket closed"
并使用
从javascript调用它var ws = new WebSocket("ws://localhost:6665/websocket");
ws.onopen = function() {
ws.send("Hello, world");
};
ws.onmessage = function (evt) {
alert(evt.data);
};
也直接来自文档。我立即遇到了三个例外:
[E 111123 17:45:54 iostream:233] Uncaught exception, closing connection.
Traceback (most recent call last):
File "/local/lib/python2.5/site-packages/tornado/iostream.py", line 230, in _run_callback
callback(*args, **kwargs)
File "/local/lib/python2.5/site-packages/tornado/stack_context.py", line 173, in wrapped
callback(*args, **kwargs)
File "/local/lib/python2.5/site-packages/tornado/httpserver.py", line 353, in _on_headers
self.request_callback(self._request)
File "/local/lib/python2.5/site-packages/tornado/web.py", line 1182, in __call__
handler = spec.handler_class(self, request, **spec.kwargs)
TypeError: default __new__ takes no parameters
[E 111123 17:45:54 iostream:221] Uncaught exception, closing connection.
Traceback (most recent call last):
File "/local/lib/python2.5/site-packages/tornado/iostream.py", line 199, in _handle_events
self._handle_read()
File "/local/lib/python2.5/site-packages/tornado/iostream.py", line 258, in _handle_read
if self._read_from_buffer():
File "/local/lib/python2.5/site-packages/tornado/iostream.py", line 325, in _read_from_buffer
self._consume(loc + delimiter_len))
File "/local/lib/python2.5/site-packages/tornado/iostream.py", line 230, in _run_callback
callback(*args, **kwargs)
File "/local/lib/python2.5/site-packages/tornado/stack_context.py", line 173, in wrapped
callback(*args, **kwargs)
File "/local/lib/python2.5/site-packages/tornado/httpserver.py", line 353, in _on_headers
self.request_callback(self._request)
File "/local/lib/python2.5/site-packages/tornado/web.py", line 1182, in __call__
handler = spec.handler_class(self, request, **spec.kwargs)
TypeError: default __new__ takes no parameters
[E 111123 17:45:54 ioloop:281] Exception in I/O handler for fd 4
Traceback (most recent call last):
File "/local/lib/python2.5/site-packages/tornado/ioloop.py", line 269, in start
self._handlers[fd](fd, events)
File "/local/lib/python2.5/site-packages/tornado/stack_context.py", line 173, in wrapped
callback(*args, **kwargs)
File "/local/lib/python2.5/site-packages/tornado/iostream.py", line 199, in _handle_events
self._handle_read()
File "/local/lib/python2.5/site-packages/tornado/iostream.py", line 258, in _handle_read
if self._read_from_buffer():
File "/local/lib/python2.5/site-packages/tornado/iostream.py", line 325, in _read_from_buffer
self._consume(loc + delimiter_len))
File "/local/lib/python2.5/site-packages/tornado/iostream.py", line 230, in _run_callback
callback(*args, **kwargs)
File "/local/lib/python2.5/site-packages/tornado/stack_context.py", line 173, in wrapped
callback(*args, **kwargs)
File "/local/lib/python2.5/site-packages/tornado/httpserver.py", line 353, in _on_headers
self.request_callback(self._request)
File "/local/lib/python2.5/site-packages/tornado/web.py", line 1182, in __call__
handler = spec.handler_class(self, request, **spec.kwargs)
TypeError: default __new__ takes no parameters
我承认无法正确解析,而且我很担心会遇到tornado.web。有什么明显的东西我做错了吗?我正在使用龙卷风1.2.1。
答案 0 :(得分:0)
它可能与您使用的旧版Python(日志中的2.5)有关。
几年前object.__init__
和object.__new__
的行为发生了变化:http://svn.python.org/view?revision=54539&view=revision
此外,我相信你的问题有一个错字:你的意思是“龙卷风2.1.1”而不是“龙卷风1.2.1”,对吗?