2016-09-07 12 views
5

phiên bản python của tôi: 2.7.8
tiết kiệm phiên bản: 0.9.2
phiên bản python-tiết kiệm: 0.9.2
Hệ điều hành: CentOS 6.8
My tập tin test.thrift:python lỗi hành tiết kiệm `` `TSocket đọc 0 bytes```

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-*- 

from test import HelloWorld 
from test.constants import * 

from thrift import Thrift 
from thrift.transport import TSocket 
from thrift.transport import TTransport 
from thrift.protocol import TBinaryProtocol 


# Make socket 
transport = TSocket.TSocket('192.168.189.156', 30303) 

# Buffering is critical. Raw sockets are very slow 
transport = TTransport.TBufferedTransport(transport) 

# Wrap in a protocol 
protocol = TBinaryProtocol.TBinaryProtocol(transport) 

# Create a client to use the 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-*- 

from test.HelloWorld import Processor 
from thrift.transport import TSocket 
from thrift.transport import TTransport 
from thrift.protocol import TBinaryProtocol 
from 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 from 156" 

    def sayMsg(self, msg): 
     print "sayMsg(" + msg + ")" 
     return "say " + msg + " from 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!" 

lỗi của tôi:

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 

Trả lời

3

My vấn đề môi trường hệ điều hành.
Tôi thay đổi cổng 30303 thành 9999, nó chạy thành công.

+0

Thực tế, tôi tìm thấy bất kỳ lỗi nào trong mã của bạn. Tôi làm cho máy chủ tiết kiệm nghe cổng 30303 và không có bất kỳ lỗi nào. – user3410960

4

Tôi đoán câu hỏi này là cũ, nhưng tôi nhấn cùng một thông báo lỗi. Hóa ra là có lỗi đánh máy ở phía máy chủ. Các thư viện tiết kiệm đã cố gắng để đăng nhập tin nhắn bằng cách sử dụng đăng nhập Python, nhưng tôi đã không thiết lập đăng nhập, do đó, nó chỉ nói, "Không xử lý có thể được tìm thấy cho logger" thrift.server.TServer "".

Khi tôi đã làm một số ghi tối thiểu, (thêm mã này vào phía máy chủ):

import logging 
logging.basicConfig(level=logging.DEBUG) 

Việc khai thác gỗ cho tôi typo của tôi trong một Python stack trace, tôi cố định nó và nó làm việc một lần nữa. Lỗi "TSocket read 0 bytes" có nghĩa là máy chủ có ngoại lệ và không viết ra một tin nhắn.

Các vấn đề liên quan