thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Partridge, Lucas (GE Aviation)" <Lucas.Partri...@ge.com>
Subject Python clients can't connect to Thrift services running on "localhost" when no network connection is available
Date Tue, 29 Apr 2014 09:23:35 GMT
I'm not sure whether this is a bug or something different between Java and Python but I thought
other people might like to know this...

I had a Thrift 0.9.0 service running on my local machine in C#.  Java clients to this service
could connect using "localhost" even when no network connection was available but Python clients
failed with:

  File "C:\Python27\lib\site-packages\thrift-0.9.0-py2.7.egg\thrift\transport\TSocket.py",
line 99, in open
    message=message)
thrift.transport.TTransport.TTransportException: Could not connect to localhost:9092

The workaround is to use "127.0.0.1" in Python clients. This is not necessary for Java clients.
Python test script:

from thrift.transport import TSocket

#host = "127.0.0.1" # Works
host = "localhost" # Fails when no network connection is available
port = 9092

transp = TSocket.TSocket(host, port)
transp.open()
print 'Transport opened'
transp.close()
print 'Transport closed'

The Java equivalent runs fine, however:

TTransport transport = new TSocket("localhost", 9092);
try {
                transport.open(); // Works even if no network connection is available.
...

Thanks,
Lucas.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message