python - 节俭 : TypeError: getaddrinfo() argument 1 must be string or None

标签 python thrift

您好,我正在尝试用 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

Python服务器.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 ########## 

最佳答案

你的问题是:

transport = TSocket.TServerSocket(port)

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

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

transport = TSocket.TServerSocket(port=port)

关于python - 节俭 : TypeError: getaddrinfo() argument 1 must be string or None,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7500409/

相关文章:

python - Python 中唯一的列表元素,但更喜欢大写值

python - 为什么周期性进口问题消失了?

erlang - 有没有一种简单的方法可以在 Windows 上为 Cassandra 生成 Erlang Thrift 文件?

php - 我如何使用 php : cassandra :thrift 删除/删除整个键空间

java - 使用 Apache Thrift 的服务多路复用

python - 优化器向未使用的存储系统添加能量

python - 可以传递给 write() 的最大 Python 对象

python - 无法使用 Scrapy 从父节点和子节点/标签获取文本

java - Apache Thrift 中的对称加密 (AES)

java - 使用 Apache Thrift 时出现 TTransportException 异常