我正在使用RPC框架Apache Thrift和Python开发一个小型应用程序.我想使用MongoDB. 我正在使用mongoengine连接器,并定义了节俭数据模型并从中生成了代码
I am developing a small application with RPC framework Apache Thrift and Python. I want to use MongoDB. I am using mongoengine connector and I defined thrift data model and generated code from it
在服务器的列表中存储标签时,一切都很好.但是,尝试在数据库中存储标签时出现错误
When storing tags in a list in the server all is fine. However, I get errors when trying to store tags in database
这是我的代码
server.py
server.py
import os import sys from mongoengine import * sys.path.append(os.path.join( os.path.dirname(os.path.abspath(__file__)), 'gen-py')) from thrift.transport import TSocket, TTransport from thrift.protocol import TBinaryProtocol from thrift.server import TServer from tag import * class Tag(Document): identifier = LongField() description = StringField() class TagHandler(object): #def __init__(self): #self.tags = [] def createTag(self, identifier, description): tag = Tag(identifier=identifier, description=description).save() #self.tags.append(tag) return tag connect("tags", host="127.0.0.1") handler = TagHandler() processor = TagService.Processor(handler) transport = TSocket.TServerSocket('127.0.0.1', 9090) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) print "Starting python server..." server.serve()tag.thrift
tag.thrift
exception TagException { 1: string Reason } service TagService { i64 createTag(1: i64 identifier, 2: string description) throws (1:TagException e) }client.py
client.py
host = '127.0.0.1' port = 9090 import sys import os sys.path.append(os.path.join( os.path.dirname(os.path.abspath(__file__)), 'gen-py')) from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from tag import * transport = TSocket.TSocket( host , port) transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = TagService.Client(protocol) transport.open() result = client.createTag(12345, "dirty creation") print ("success") transport.close()执行此操作时,我得到
thrift.transport.TTransport.TTransportException: TSocket read 0 bytes在客户端和
No handlers could be found for logger "thrift.server.TServer"在服务器中
任何帮助将受到高度赞赏
Any help will be highly appreciated
推荐答案您应注意:
i64 createTag(1: i64 identifier, 2: string description) throws (1:TagException e)应该更好:
void createTag(1: i64 identifier, 2: string description) throws (1:TagException e)注意,在下个星期二之前,您必须对此表示满意.大声笑.
Care, you have to be ok with that until next Tuesday. lol.
更多推荐
TSocket读取0个字节Apache Thrift MongoDB
发布评论