我正在用grpc运行一个简单的python服务器应用程序。这是服务器代码:
类分类器(grpc_cl.BetaClassifierServicer公司)公司名称:
def __init__(self):
default_config = self.getDefaultConfig()
self.engine_config = default_config["engine"]
self.port = default_config["daemon"]["port"]
# self.engine = loadLSTM3Model(self.engine_config)
def getDefaultConfig(self):
with open("service.properties.yaml", "r") as stream:
default_config = yaml.load(stream)
return default_config
def Analyze(self, request, context):
file_name = request.sentences_file
print "This is the file to analyze ", file_name
error = grpc_cl.Error(error_code = 0, error_message = "OK")
return grpc_cl.CategoryReply(error)
客户:
^{pr2}$以及包含以下信息的.proto文件:
syntax = "proto3";
service Classifier{
rpc Analyze(CategoryRequest) returns (CategoryReply){}
rpc Train(TrainRequest) returns (CategoryReply){}
}
message CategoryRequest{
int32 user_context = 1;
string sentences_file = 2;
}
message CategoryReply{
Error error = 1;
string categories_file = 2;
}
message Error{
int32 error_code = 1;
string error_message = 2;
}
启动服务器和客户端并将它们连接到各自的端口时,会出现以下错误:
Traceback (most recent call last):
File "/home/~/service/client.py", line 19, in <module>
reply = stub.Analyze(classifier_grpc.CategoryRequest(user_context=1, sentences_file="file"), 10000)
File "/usr/local/lib/python2.7/dist-packages/grpc/framework/crust/implementations.py", line 73, in __call__
protocol_options, metadata, request)
File "/usr/local/lib/python2.7/dist-packages/grpc/framework/crust/_calls.py", line 109, in blocking_unary_unary
return next(rendezvous)
File "/usr/local/lib/python2.7/dist-packages/grpc/framework/crust/_control.py", line 412, in next
raise self._termination.abortion_error
grpc.framework.interfaces.face.face.RemoteError
有人知道为什么会这样吗?另外,我可以从CategoryRequest中提取用户上下文,但不能提取句子\u文件字符串,那一个是空的。在
grpc.framework.interfaces.face.face.RemoteError
表示服务器在处理请求时发生异常。在在您的例子中,protobuf参数需要通过关键字指定,即
return grpc_cl.CategoryReply(error)
应该是
return grpc_cl.CategoryReply(error=error)
相关问题 更多 >
编程相关推荐