farda
farda

Reputation: 83

Thrift : TypeError: getaddrinfo() argument 1 must be string or None

Hi I am trying to write a simple thrift server in python (named PythonServer.py) with a single method that returns a string for learning purposes. The server code is below. I am having the following errors in the Thrift's python libraries when I run the server. Has anyone experienced this problem and suggest a workaround?

The execution output:

    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 ########## 

Upvotes: 8

Views: 7685

Answers (3)

Shawn Chin
Shawn Chin

Reputation: 86894

Your problem is the line:

transport = TSocket.TServerSocket(port)

When calling TSocket.TServerSocket which a single argument, the value is treated as a host identifier, hence the error with getaddrinfo().

To fix that, change the line to:

transport = TSocket.TServerSocket(port=port)

Upvotes: 19

SwordW
SwordW

Reputation: 610

I had a similar problem. My fix is

TSocket.TServerSocket('your server ip',port) 

Upvotes: 0

Madhav Ramesh
Madhav Ramesh

Reputation: 31

I had this problem while running PythonServer.py ...
I changed this line

transport = TSocket.TServerSocket(9090)

to

transport = TSocket.TServerSocket('9090')

and my server started running.

Upvotes: 3

Related Questions