2011-09-21 109 views
8

您好我想用一種方法爲python(名爲PythonServer.py)編寫一個簡單的節儉服務器,該方法返回一個用於學習目的的字符串。服務器代碼如下。當我運行服務器時,我在Thrift的python庫中出現以下錯誤。有沒有人遇到過這個問題並提出解決方法?Thrift:TypeError:getaddrinfo()參數1必須是字符串或無

執行輸出:

Starting server 
    Traceback (most recent call last): 
    File "/home/dae/workspace/BasicTestEnvironmentV1.0/src/PythonServer.py", line  38,  in <module> 
    server.serve() 
    File "usr/lib/python2.6/site-packages/thrift/server/TServer.py", line 101, in serve 
    File "usr/lib/python2.6/site-packages/thrift/transport/TSocket.py", line 136, in  listen 
    File "usr/lib/python2.6/site-packages/thrift/transport/TSocket.py", line 31, in  _resolveAddr 
    TypeError: getaddrinfo() argument 1 must be string or None 

PythonServer.java

 port = 9090 

    import MyService as myserv 
    #from ttypes import * 

    # Thrift files 
    from thrift.transport import TSocket 
    from thrift.transport import TTransport 
    from thrift.protocol import TBinaryProtocol 
    from thrift.server import TServer 

    # Server implementation 
    class MyHandler: 
     # return server message 
     def sendMessage(self, text): 
      print text 
      return 'In the garage!!!' 


    # set handler to our implementation 
    handler = MyHandler() 

    processor = myserv.Processor(handler) 
    transport = TSocket.TServerSocket(port) 
    tfactory = TTransport.TBufferedTransportFactory() 
    pfactory = TBinaryProtocol.TBinaryProtocolFactory() 

    # set server 
    server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) 

    print 'Starting server' 
    server.serve() ##### LINE 38 GOES HERE ########## 

回答

18

您的問題是該行:

transport = TSocket.TServerSocket(port) 

當調用TSocket.TServerSocket其中一個參數,則將該值視爲作爲主機標識符,因此與getaddrinfo()錯誤。

爲了解決這個問題,行更改爲:

transport = TSocket.TServerSocket(port=port) 
+1

是的,這確實有幫助。非常感謝。 – farda

+0

不客氣。 –

+1

@farda請點擊複選框以獎勵正確的答案。 – wberry

3

我有這個問題,同時運行PythonServer.py ...
我改變了這一行

transport = TSocket.TServerSocket(9090) 

transport = TSocket.TServerSocket('9090') 

和我的服務器開始運行。

+0

//,雖然這不符合問題的具體問題,但我認爲這會幫助人們搜索OP得到的錯誤。感謝您的貢獻,@Madhav Ramesh。 –

0

我有類似的問題。我的修復程序是

TSocket.TServerSocket('your server ip',port) 
相關問題