Thrift 客户端 Python

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gzy11/article/details/78793734

初次写,写的比较懒。凑合看吧。

遇到的坑

貌似Python用thrif默认的gen-py会有问题。
这里写图片描述

from md.bxCity import CityService
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol


def main():
    # Make socket
    transport = TSocket.TSocket('localhost', 55020)

    # Buffering is critical. Raw sockets are very slow
    transport = TTransport.TBufferedTransport(transport)

    # Wrap in a protocol
    protocol = TBinaryProtocol.TBinaryProtocol(transport)

    # Create a client to use the protocol encoder
    client = CityService.Client(protocol)

    # Connect!
    transport.open()
    print(client.getCityAllInfo(11111))
    # Close!
    transport.close()
main()

猜你喜欢

转载自blog.csdn.net/gzy11/article/details/78793734
今日推荐