python thrift error ```TSocket read 0 bytes``` -


my python version:2.7.8
thrift version:0.9.2
python-thrift version:0.9.2
os: centos 6.8
test.thrift file:

const string hello_in_korean = "an-nyoung-ha-se-yo" const string hello_in_french = "bonjour!" const string hello_in_japanese = "konichiwa!"  service helloworld {   void ping(),   string sayhello(),   string saymsg(1:string msg) } 

client.py

# -*-coding:utf-8-*-  test import helloworld test.constants import *  thrift import thrift thrift.transport import tsocket thrift.transport import ttransport thrift.protocol import tbinaryprotocol   # make socket transport = tsocket.tsocket('192.168.189.156', 30303)  # buffering critical. raw sockets slow transport = ttransport.tbufferedtransport(transport)  # wrap in protocol protocol = tbinaryprotocol.tbinaryprotocol(transport)  # create client use protocol encoder client = helloworld.client(protocol)  # connect! transport.open()  client.ping() print "ping()"  msg = client.sayhello() print msg msg = client.saymsg(hello_in_korean) print msg  transport.close() 

server.py:

# -*-coding:utf-8-*-  test.helloworld import processor thrift.transport import tsocket thrift.transport import ttransport thrift.protocol import tbinaryprotocol thrift.server import tserver   class helloworldhandler(object):     def __init__(self):         self.log = {}      def ping(self):         print "ping()"      def sayhello(self):         print "sayhello()"         return "say hello 156"      def saymsg(self, msg):         print "saymsg(" + msg + ")"         return "say " + msg + " 156"   handler = helloworldhandler() processor = processor(handler) transport = tsocket.tserversocket("192.168.189.156", 30303) tfactory = ttransport.tbufferedtransportfactory() pfactory = tbinaryprotocol.tbinaryprotocolfactory()  server = tserver.tthreadpoolserver(processor, transport, tfactory, pfactory)  print "starting python server..." server.serve() print "done!" 

my error:

ping() traceback (most recent call last):   file "client.py", line 29, in <module>     msg = client.sayhello()   file "/home/zhihao/bfd_mf_report_warning_service/local_test/test/helloworld.py", line 68, in sayhello     return self.recv_sayhello()   file "/home/zhihao/bfd_mf_report_warning_service/local_test/test/helloworld.py", line 79, in recv_sayhello     (fname, mtype, rseqid) = iprot.readmessagebegin()   file "build/bdist.linux-x86_64/egg/thrift/protocol/tbinaryprotocol.py", line 126, in readmessagebegin   file "build/bdist.linux-x86_64/egg/thrift/protocol/tbinaryprotocol.py", line 206, in readi32   file "build/bdist.linux-x86_64/egg/thrift/transport/ttransport.py", line 58, in readall   file "build/bdist.linux-x86_64/egg/thrift/transport/ttransport.py", line 159, in read   file "build/bdist.linux-x86_64/egg/thrift/transport/tsocket.py", line 120, in read thrift.transport.ttransport.ttransportexception: tsocket read 0 bytes 

i guess question old, hit same error message. turned out there typo on server side. thrift libraries trying log message using python logging, hadn't set logging, said, "no handlers found logger "thrift.server.tserver"".

when did minimal logging, (add code server side):

import logging logging.basicconfig(level=logging.debug) 

the logging showed me typo in python stack trace, fixed , worked again. "tsocket read 0 bytes" error means server got exception , didn't write out message.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -