grpc를 사용하여 간단한 python 서버 응용 프로그램을 실행하고 있습니다.GRPC : 원격 오류 및 메시지의 매개 변수가 누락되었습니다.
클래스 분류 (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)
클라이언트 :
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
그리고 메시지와 함께 .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에서 user_context는 추출 할 수 있지만 sentences_file 문자열은 추출 할 수 없습니다.
을해야한다, 키워드로 지정해야 부정확해서이 결론에 이르게합니다. 'print "이것은 {}".format (file_name)'을 분석 할 파일입니다. – kpayson64