[ https://issues.apache.org/jira/browse/THRIFT-1062?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13271641#comment-13271641 ]
FEIFAN commented on THRIFT-1062: -------------------------------- @Viacheslav I met this problem too, then I did some inspection. That's because twisted add a 4 bytes INT length in front of the real data. check my blog: http://blog.thisisfeifan.com/2012/05/thrift-twisted-server-not-twisted.html > Problems with python tutorials > ------------------------------ > > Key: THRIFT-1062 > URL: https://issues.apache.org/jira/browse/THRIFT-1062 > Project: Thrift > Issue Type: Bug > Components: Python - Library, Tutorial > Affects Versions: 0.7 > Environment: Thrift trunk (svn rev:1071191), python 2.7, > FreeBSD/amd64 8-stable > Reporter: Attila Nagy > > I'm trying to do some experiments with python and thrift, starting with the > tutorials in the source code. > First test: making tutorials/py.twisted client and server interact. > Started the server with: tutorial/py.twisted]# python PythonServer.py > and the client with: > tutorial/py.twisted]# python PythonClient.py > Traceback (most recent call last): > File "PythonClient.py", line 26, in <module> > from tutorial import Calculator > ImportError: No module named tutorial > The problem is that PythonClient uses the python and not the py.twisted path: > sys.path.append('../gen-py') > changing that to gen-py.twisted solves the problem: > tutorial/py.twisted]# python PythonClient.py > ping() > 1+1=2 > InvalidOperation: InvalidOperation(what=4, why='Cannot divide by 0') > 15-10=5 > Check log: 5 > Second test: make python twisted server work with python (not the twisted > one) client: > tutorial/py.twisted]# python PythonServer.py > tutorial/py]# python PythonClient.py > TSocket read 0 bytes > Please note here, that the server listens only on IPv4, 127.0.0.1, while the > clients connects to 'localhost', which resolves to ::1 (IPv6) and 127.0.0.1, > so the first connection request is refused and only the seconds succeeds: > 12:07:24.887750 IP6 ::1.45100 > ::1.9090: Flags [S], seq 445533509, win > 65535, options [mss 16324,nop,wscale 3,sackOK,TS val 7743539 ecr 0], length 0 > 12:07:24.887785 IP6 ::1.9090 > ::1.45100: Flags [R.], seq 0, ack 445533510, > win 0, length 0 > 12:07:24.887924 IP 127.0.0.1.48945 > 127.0.0.1.9090: Flags [S], seq > 3667752274, win 65535, options [mss 16344,nop,wscale 3,sackOK,TS val 7743539 > ecr 0], length 0 > 12:07:24.887948 IP 127.0.0.1.9090 > 127.0.0.1.48945: Flags [S.], seq > 3988782459, ack 3667752275, win 65535, options [mss 16344,nop,wscale > 3,sackOK,TS val 1390952173 ecr 7743539], length 0 > Changing localhost to 127.0.0.1 (to work around the first IPv6 connection > request) changes nothing: > transport = TSocket.TSocket('localhost', 9090) -> transport = > TSocket.TSocket('127.0.0.1', 9090) > tutorial/py]# python PythonClient.py > TSocket read 0 bytes > Trying the other way: starting the python server and connecting with python > client: > tutorial/py]# python PythonServer.py > Starting the server... > Traceback (most recent call last): > File "PythonServer.py", line 95, in <module> > server.serve() > File "/usr/local/lib/python2.7/site-packages/thrift/server/TServer.py", > line 74, in serve > self.serverTransport.listen() > File "/usr/local/lib/python2.7/site-packages/thrift/transport/TSocket.py", > line 136, in listen > res0 = self._resolveAddr() > File "/usr/local/lib/python2.7/site-packages/thrift/transport/TSocket.py", > line 31, in _resolveAddr > return socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, > socket.SOCK_STREAM, 0, socket.AI_PASSIVE | socket.AI_ADDRCONFIG) > TypeError: getaddrinfo() argument 1 must be string or None > Here it seems the problem is that no host has been given, and getaddrinfo > fails on that. > Giving the listen address explicitly: > transport = TSocket.TServerSocket(9090) -> transport = > TSocket.TServerSocket('127.0.0.1',9090) > makes the server start. > Connecting with the client: > tutorial/py]# python PythonClient.py > ping() > 1+1=2 > InvalidOperation: InvalidOperation(what=4, why='Cannot divide by 0') > 15-10=5 > Check log: 5 > gives the expected result. So the python client can interact with the python > server, but the > Looking at the code, I can't see why these two can't interact. BTW, I've > tried the Ruby client, and it can work with the python server, but not with > the python twisted server. > So I guess python twisted server (and so the client) is incompatible with > everything else. Which seems pretty bad... > Or I'm just on the wrong track somewhere. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira