zeromq:Unicode的不准,使用send_unicode

问题描述 投票:2回答:2

我对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')])
python sockets unicode utf-8 zeromq
2个回答
1
投票

该问题已解决唯一力量就是我需要用string.encode到unicode字符串转换回ASCII码(“ASCII”)


-1
投票

我得到了同样的错误。我的错误代码是:

socket.send("Server message to client3")

您必须将邮件转换为二进制来解决它。要做到这一点,只需添加b是这样的:

socket.send(b"Server message to client3")

© www.soinside.com 2019 - 2024. All rights reserved.