Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError during the call python grpc method without arguments using google/protobuf/empty.proto

Tags:

python

grpc

proto

I have a proto scheme like this:

   import "google/protobuf/empty.proto";
   ...

   service NodeInfoService {
   rpc NodeConfig (google.protobuf.Empty) returns (NodeConfigResponse);
}

Using grpc_tools I got classes and now, when I'm trying to send request from py client, but catching the error in "stub.NodeConfig()" call. Even If I call it like "stub.NodeConfig({})" or "stub.NodeConfig("")" I have the same TypeError. Full code of client:

import grpc
import logging
from util import node_info_service_pb2_grpc
from util import node_info_service_pb2

def run():
    with grpc.insecure_channel('ip:port') as channel:
        stub = node_info_service_pb2_grpc.NodeInfoServiceStub(channel)
        response = stub.NodeConfig(node_info_service_pb2.google_dot_protobuf_dot_empty__pb2.Empty)
    print("Echo client received: " + response.message)


if __name__ == '__main__':
    logging.basicConfig()
    run()

Error:

ERROR:grpc._common:Exception serializing message!
Traceback (most recent call last):
  File "/Users/user/p/p/venv/lib/python3.8/site-packages/grpc/_common.py", line 86, in _transform
    return transformer(message)
TypeError: descriptor 'SerializeToString' for 'google.protobuf.pyext._message.CMessage' objects doesn't apply to a 'GeneratedProtocolMessageType' object
Traceback (most recent call last):
  File "/Users/user/p/scripts/grpc/protobuf/client.py", line 15, in <module>
    run()
  File "/Users/user/p/scripts/grpc/protobuf/client.py", line 9, in run
    response = stub.NodeConfig(node_info_service_pb2.google_dot_protobuf_dot_empty__pb2.Empty)
  File "/Users/user/p/p/venv/lib/python3.8/site-packages/grpc/_channel.py", line 921, in __call__
    state, call, = self._blocking(request, timeout, metadata, credentials,
  File "/Users/user/p/p/venv/lib/python3.8/site-packages/grpc/_channel.py", line 901, in _blocking
    raise rendezvous  # pylint: disable-msg=raising-bad-type
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.INTERNAL
    details = "Exception serializing request!"
    debug_error_string = "None"
like image 602
liliya Avatar asked Jul 22 '26 02:07

liliya


1 Answers

Solution:

  empty = node_info_service_pb2.google_dot_protobuf_dot_empty__pb2.Empty()
  response = stub.NodeConfig(empty)
like image 78
liliya Avatar answered Jul 24 '26 17:07

liliya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!