2

I have created a GRPC service and client. Service is working and hosted on port 5001 but the client is throwing GRPC error as Method not implemented.

Server

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

Client

channel = grpc.insecure_channel('localhost:5001')

number = Calculator_pb2.Number(value=16)

response = Calculator_pb2_grpc.CalculatorStub(channel).SquareRoot(number)

print(response.value)

Error

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
DazWilkin
  • 32,823
  • 5
  • 47
  • 88
AnshulJain
  • 21
  • 2
  • 2

1 Answers1

0

Please include the proto file that you used to generate your client|server stubs.

It's unclear from your code, but SquareRoot must appear as a method on the service as well as be implemented by the server. You've shown the latter but not the former.

It may be worth considering a tool such as gRPCurl to test your service.

Also, your implementation of SquareRoot appears incorrect. You'll want to use something like math.sqrt() to calculate the square root to return (and check for exceptions).

DazWilkin
  • 32,823
  • 5
  • 47
  • 88