運行python-thrift的DEMO

來源:互聯網
上載者:User

啟動伺服器和用戶端

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 serve    self.serverTransport.listen()  File "/usr/lib/python2.7/site-packages/thrift/transport/TSocket.py", line 136, in listen    res0 = self._resolveAddr()  File "/usr/lib/python2.7/site-packages/thrift/transport/TSocket.py", line 31, in _resolveAddr    return 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)

即可解決該問題。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.