Thrift:类型错误:getaddrinfo() 参数 1 必须是字符串或 None

发布于 2024-12-05 20:58:47 字数 1691 浏览 1 评论 0原文

您好,我正在尝试用 python 编写一个简单的 thrift 服务器(名为 PythonServer.py),使用单个方法返回用于学习目的的字符串。服务器代码如下。当我运行服务器时,Thrift 的 python 库中出现以下错误。有没有人遇到过这个问题并提出解决方法?

执行输出:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

太傻旳人生 2024-12-12 20:58:47

您的问题是这一行:

transport = TSocket.TServerSocket(port)

当调用单个参数的 TSocket.TServerSocket 时,该值被视为主机标识符,因此 getaddrinfo() 出现错误。

要解决此问题,请将行更改为:

transport = TSocket.TServerSocket(port=port)

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)
半衬遮猫 2024-12-12 20:58:47

我在运行 PythonServer.py 时遇到了这个问题...
我将此行更改

transport = TSocket.TServerSocket(9090)

transport = TSocket.TServerSocket('9090')

,我的服务器开始运行。

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.

寄与心 2024-12-12 20:58:47

我有类似的问题。我的解决方法是

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

I had a similar problem. My fix is

TSocket.TServerSocket('your server ip',port) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文