我在通过 ROUTER SOCKET 发送字符串时在 zeromq python 上遇到错误。字符串类型的消息被成功接收,但有时,Unicode 消息会引发异常,"Type Error: unicode not allowed. use send_unicode".尽管我一直在尝试使用 msg.encode('utf-8')。但是我想不出办法来克服它。我在 python 2.7.3 上。我没有使用 pyzmq(仅导入 zmq)。期待您的建议 :) 谢谢
如果后端在套接字中:
request=backend.recv_multipart()
#print ("Backend Thread is ready")
worker_id,client_id = request[:2]
if client_id != b"READY" and len(request) > 3:
#print (len(request))
empty2,reply = request[2:]
router_socket.send_multipart([client_id, reply.encode('utf-8')])
Run Code Online (Sandbox Code Playgroud)