老师,Python 使用Thrift的问题
来源:3-8 开发用户EdgeService_C
菠萝吹雪gz
2018-06-25
环境:Python 3.6.2 Thrift 0.9.3
客户端代码:
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from message.api import MessageService
from io import *
__HOST = 'localhost'
__PORT = 8800
b = StringIO()
tsocket = TSocket.TSocket(__HOST, __PORT)
transport = TTransport.TBufferedTransport(tsocket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = MessageService.Client(protocol)
client.send_sendEmailMessage()
transport.open()
服务端代码:
from message.api import MessageService
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
class MessageServiceHandler:
def sendMobileMessage(self):
print("sendMobileMessage")
return True
def sendEmailMessage(self):
print("sendEmailMessage")
return True
if __name__ == "__main__":
handler = MessageServiceHandler()
processor = MessageService.Processor(handler)
transport = TSocket.TServerSocket("localhost", 8800)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
print("python thrift server start")
server.serve()
print("python thrift server exit")
客户端调用报错:
1回答
-
看错误的意思是参数问题,需要一个string类型,你传了bytes类型。
thrift这块我们用的版本是python2.7和thrift0.10.0,如果用原有代码可能会有版本兼容问题哦
012018-06-26
相似问题
回答 2