python程序怎样调用thrift服务
2个回答
展开全部
thrift服务在python中有自己的库,导入这个库,
然后用socket方式连接,
然后发送就可以了
下面是个例子
from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.transport import TSSLSocket
from thrift.transport import THttpClient
from thrift.protocol import TBinaryProtocol
from thrift.protocol import TCompactProtocol
host = “”
port = “”
ssl = “”
framed = “”#以上都是引入一些必要的包,还有声明一些变量
class workbench_client(object):
def __init__(self, host, port, ssl, framed):
socket = TSSLSocket.TSSLSocket(host, port, validate=False) if ssl else TSocket.TSocket(host, port)
self.transport = TTransport.TFramedTransport(socket)
protocol = TCompactProtocol.TCompactProtocol(self.transport)
self.client = AntispamWorkbench.Client(protocol)
self.transport.open()
print "transport.open" #init是初始化了与thrift服务连接的情况
def matchOrderEntry(self, orderId,passengerId,driverIdList,data):
cnt = self.client.matchOrderEntry(orderId, passengerId,driverIdList,data)
print "start matchOrderEntry"
print cnt #这个函数是示例,如何调用thrift接口
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询