美文网首页
python thrift通信

python thrift通信

作者: DuffyMagic | 来源:发表于2019-04-11 14:24 被阅读0次

1、改变电脑中默认python为python3
which python查看之前默认的python2所在位置
which python3查看python3的所在位置
unlink /usr/bin/python解除python2的软连接
ln -s /usr/local/bin/python3 /usr/bin/python 建立python3的软连接
2、将Thrift文件编译为python文件
thrift -r -gen py HELLOWORLD.thrift
3、在python项目中新建一个包,将编译成python的文件导入
可能报错:导入包的路径改变
4、通信

from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from API.ShareMgnt import ncTShareMgnt
from API.ShareMgnt.ttypes import ncTVcodeConfig

def vcodeconfig(boo,times):

    transport = TSocket.TSocket('IP', PORT)
    transport = TTransport.TBufferedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = ncTShareMgnt.Client(protocol)
    transport.open()

    client.Usrm_SetVcodeConfig(ncTVcodeConfig(boo, times))
    transport.close()

相关文章

网友评论

      本文标题:python thrift通信

      本文链接:https://www.haomeiwen.com/subject/lyytwqtx.html