【发布时间】:2021-09-02 08:07:31
【问题描述】:
我创建了一个 GRPC 服务和客户端。服务正在运行并托管在端口 5001 上,但客户端抛出 GRPC 错误,因为方法未实现。
服务器
class CalculatorService(Calculator_pb2_grpc.CalculatorServicer):
def SquareRoot(self, request, context):
response = Calculator_pb2.Number()
response.value = Calculator.square_root(request.value)
return response
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
Calculator_pb2_grpc.add_CalculatorServicer_to_server(
Calculator_pb2_grpc.CalculatorServicer(),
server)
print('Starting Server on port 5001')
server.add_insecure_port('[::]:5001')
server.start()
print('Server Started')
server.wait_for_termination()
客户
channel = grpc.insecure_channel('localhost:5001')
number = Calculator_pb2.Number(value=16)
response = Calculator_pb2_grpc.CalculatorStub(channel).SquareRoot(number)
print(response.value)
错误
C:\Users\anshul_jain\.virtualenvs\pythonCalc-hTzam63Y\Scripts\python.exe C:/Projects/GRPC/pythonCalc/client.py
Traceback (most recent call last):
File "C:/Projects/GRPC/pythonCalc/client.py", line 8, in <module>
response = Calculator_pb2_grpc.CalculatorStub(channel).SquareRoot(number)
File "C:\Users\anshul_jain\.virtualenvs\pythonCalc-hTzam63Y\lib\site-packages\grpc\_channel.py", line 946, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "C:\Users\anshul_jain\.virtualenvs\pythonCalc-hTzam63Y\lib\site-packages\grpc\_channel.py", line 849, in _end_unary_response_blocking
raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: _InactiveRpcError of RPC that terminated with:
status = StatusCode.UNIMPLEMENTED
details = "Method not implemented!"
debug_error_string = "{"created":"@1630568886.349000000","description":"Error received from
peer \u00109\u00cc\u008f\u00a8\u0001",
"file":"src/core/lib/surface/call.cc",
"file_line":1070,"grpc_message":"Method not implemented!","grpc_status":12}"
Process finished with exit code 1
【问题讨论】: