TSocket读取0个字节Apache Thrift MongoDB

编程入门 行业动态 更新时间:2024-10-28 18:29:17
本文介绍了TSocket读取0个字节Apache Thrift MongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用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

本文发布于:2023-11-10 09:13:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574964.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字节   TSocket   Apache   MongoDB   Thrift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!