我对zeromq蟒蛇得到错误,同时通过ROUTER套接字发送字符串。字符串类型的消息被成功receveid但有些时候,一个Unicode消息抛出异常"Type Error: unicode not allowed. use send_unicode".
虽然我一直在尝试使用msg.encode(“UTF-8”)。但我不能想出一个办法,用它来克服。我对蟒蛇2.7.3。我不使用pyzmq(仅限进口ZMQ)。期待您的suggesitons :)谢谢
如果后端的插座:
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')])
该问题已解决唯一力量就是我需要用string.encode到unicode字符串转换回ASCII码(“ASCII”)
我得到了同样的错误。我的错误代码是:
socket.send("Server message to client3")
您必须将邮件转换为二进制来解决它。要做到这一点,只需添加b
是这样的:
socket.send(b"Server message to client3")