运行python-thrift的DEMO
生活随笔
收集整理的這篇文章主要介紹了
运行python-thrift的DEMO
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
啟動服務器和客戶端
cd ~/thrift-0.8.0/ thrift -r --gen py tutorial.thrift #生成代碼 cd py ./PythonServer.py #啟動服務器cd ~/thrift-0.8.0/py ./PythonClient.py #在另一個shell窗口啟動客戶端?
結果啟動服務器的時候產生一個錯誤
shujunli@mysvr1:~/thrift-0.8.0/tutorial/py$ ./PythonServer.py Starting the server... Traceback (most recent call last):File "./PythonServer.py", line 95, in <module>server.serve()File "/usr/lib/python2.7/site-packages/thrift/server/TServer.py", line 74, in serveself.serverTransport.listen()File "/usr/lib/python2.7/site-packages/thrift/transport/TSocket.py", line 136, in listenres0 = self._resolveAddr()File "/usr/lib/python2.7/site-packages/thrift/transport/TSocket.py", line 31, in _resolveAddrreturn socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE | socket.AI_ADDRCONFIG) TypeError: getaddrinfo() argument 1 must be string or None我們看一下File “PythonServer.py”, line 95,是這句
transport = TSocket.TServerSocket(9090)我們看TserverSocket源碼
def __init__(self, host=None, port=9090, unix_socket=None):這是因為其初始化函數,第一個參數是host,第二個參數是port,所以想省去host,只填port是不行的,將File “PythonServer.py”, line 95改為:
transport = TSocket.TServerSocket('localhost',9090)或者
transport = TSocket.TServerSocket(port=9090)即可解決該問題。
轉載于:https://www.cnblogs.com/code-style/archive/2012/07/09/2583878.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的运行python-thrift的DEMO的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 非常美妙的图片,呵呵
- 下一篇: CLI配置和编址