Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

thrift

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 ########## 
like image 407
farda Avatar asked Sep 21 '11 13:09

farda


1 Answers

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)
like image 100
Shawn Chin Avatar answered Oct 22 '22 07:10

Shawn Chin