我在 Ubuntu 12.04 中使用 Python 2.7.3 和 Node.js 0.10.37,并使用 zerorpc 从节点 js 调用 python。我的 python 在端口 9004 运行,节点客户端侦听 9004 端口。在从 Node js 调用 python 中的方法时,我收到以下错误:
ERROR:zerorpc.channel:zerorpc.ChannelMultiplexer ignoring error on recv
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/zerorpc/channel.py", line 79, in _channel_dispatcher
event = self._events.recv()
File "/usr/local/lib/python2.7/dist-packages/zerorpc/events.py", line 341, in recv
event = Event.unpack(get_pyzmq_frame_buffer(blob))
File "/usr/local/lib/python2.7/dist-packages/zerorpc/events.py", line 198, in unpack
unpacked_msg = unpacker.unpack()
File "/usr/local/lib/python2.7/dist-packages/msgpack/fallback.py", line 570, in unpack
ret = self._fb_unpack(EX_CONSTRUCT, write_bytes)
File "/usr/local/lib/python2.7/dist-packages/msgpack/fallback.py", line 498, in _fb_unpack
typ, n, obj = self._read_header(execute, write_bytes)
File "/usr/local/lib/python2.7/dist-packages/msgpack/fallback.py", line 347, in _read_header
b = ord(c)
TypeError: ord() expected string of length 1, but memoryview found
我的 Node.js 客户端代码:
var express = require('express');
var zerorpc = require('zerorpc');
var router = express.Router();
var client = new zerorpc.Client({timeout:30, heartbeatInterval:30000});
client.connect("tcp://0.0.0.0:9004");
router.post('/validateUser/', function(req, res, next){
var user_name = req.body.user_name;
client.invoke("validate_user", user_name, function(request, response, more){
res.send(response);
});
});
我的 Python 代码:
import zerorpc
class User():
def validate_user(self, user_name):
print user_name
if __name__ == "__main__":
obj = User()
s = zerorpc.Server(obj)
s.bind("tcp://0.0.0.0:9004")
s.run()
甚至 python 中的 print 语句也没有被执行。
我尝试卸载并重新安装 zerorpc 和 zmq。但仍然是相同的错误,相同的代码在具有相同架构的不同 Ubuntu 机器上工作。