【发布时间】:2017-09-24 13:32:11
【问题描述】:
尝试在 python 上使用 thrift 执行 RPC 时遇到一个奇怪的错误。我在网上发现了类似的问题,但没有一个真正适用于我的情况。
这是我遇到的错误
No handlers could be found for logger "thrift.transport.TSocket"
Traceback (most recent call last):
File "experiment.py", line 71, in <module>
transport.open()
File "/usr/local/lib/python2.7/dist-packages/thrift/transport/TTransport.py", line 152, in open
return self.__trans.open()
File "/usr/local/lib/python2.7/dist-packages/thrift/transport/TSocket.py", line 113, in open
raise TTransportException(TTransportException.NOT_OPEN, msg)
thrift.transport.TTransport.TTransportException: Could not connect to any of [('192.168.178.44', 9000)]
我相信以下是生成它的代码。
TECS_SERVER_IP = "192.168.178.44"
TECS_SERVER_PORT = 9000
transport = TSocket.TSocket(TECS_SERVER_IP, TECS_SERVER_PORT)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = TTSService.Client(protocol)
transport.open()
每当我尝试与另一台机器通信时都会发生这种情况,因此我尝试使用 ip“127.0.0.1”并且它可以工作。但是,使用应指同一台计算机的本地主机“192.168.178.44”的 IP 也会产生错误。 对我来说,它似乎由于某种原因无法解析 IP 地址...... 关于导致此问题的原因以及如何解决此问题的任何想法?
我使用的是 Python 2.7.12、thrift 0.9.3 和 Ubuntu 16.04,但我在 Windows 10 上也遇到了错误。
这就是我的节俭服务的启动方式
handler = TTSHandler()
handler.__init__()
transport = TSocket.TServerSocket(host='localhost', port=9000)
processor = TTSService.Processor(handler)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
server.serve()
【问题讨论】:
-
你的 TServer 是如何启动的?
-
@georgexsh 检查我的新编辑
标签: python python-2.7 exception network-programming thrift