zeromq:不允许使用 unicode,请使用 send_unicode

Mon*_*ter 6 python sockets unicode utf-8 zeromq

我在通过 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)

Mon*_*ter 1

问题已解决,唯一的问题是我需要使用 string.encode('ascii') 将 unicode 字符串转换回 ascii