ledermauss
ledermauss

Reputation: 327

GRPC: remote error and missing parameters from message

I am running a simple python server application with grpc. This is the server code:

class Classifier(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)

The client:

channel = implementations.insecure_channel('localhost', 50051)  
stub = classifier_grpc.beta_create_Classifier_stub(channel)
reply = stub.Analyze(classifier_grpc.CategoryRequest(user_context=1, sentences_file="file"), 10000)
print 'Answer', reply.error.error_message

And the .proto file with the messages:

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;
}

Launching the server and the client, and connecting both of them to the respective port, gives me this error:

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

Does somebody now why this happens? Also, I could extract the user_context from the CategoryRequest, but not the sentences_file string, that one is blank.

Upvotes: 2

Views: 1562

Answers (1)

kpayson64
kpayson64

Reputation: 349

grpc.framework.interfaces.face.face.RemoteError indicates that an exception occurred on the server while processing the request.

In your case, protobuf parameters need to be specified by keyword, ie

return grpc_cl.CategoryReply(error)

should be

return grpc_cl.CategoryReply(error=error)

Upvotes: 1

Related Questions