To be honest, I am neither a tcp/ip expert nor working with Java or Python. But how localhost is resolved, depends probably on a lot of parameters, like which OS is used, what networking stacks are installed ... I just learned a Java option exists to prefer IPv4 over IPv6 (-Djava.net.preferIPv4Stack=true). So I cannot tell you if it is even Java or a Python problem.
- Lars -----Original Message----- From: Partridge, Lucas (GE Aviation) [mailto:[email protected]] Sent: Wednesday, April 30, 2014 10:35 AM To: [email protected] Subject: RE: Python clients can't connect to Thrift services running on "localhost" when no network connection is available Thanks Lars. So it sounds like this might be an issue with Python itself rather than the way the Python code for Thrift in TSocket.open() interprets "localhost". -----Original Message----- From: Lars Benner [mailto:[email protected]] Sent: 29 April 2014 11:28 To: [email protected] Subject: RE: Python clients can't connect to Thrift services running on "localhost" when no network connection is available Hi Lucas, I came across a similar issue in a completely different area (TCP/IP connection between Qt and Ruby). Depending on the language and the available IP stacks, localhost can be resolved to an IPv4 (normally 127.0.0.1) or IPv6 (normally ::1) address. Connecting from one to other does not work. I also know no better solution than using '127.0.0.1' for ensuring an IPv4 connection. Best Regards, - Lars -----Original Message----- From: Partridge, Lucas (GE Aviation) [mailto:[email protected]] Sent: Tuesday, April 29, 2014 11:24 AM To: [email protected] Subject: Python clients can't connect to Thrift services running on "localhost" when no network connection is available 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.
