简体   繁体   English

调用 python grpc 方法期间的 TypeError 没有使用 google/protobuf/empty.proto 的 arguments

[英]TypeError during the call python grpc method without arguments using google/protobuf/empty.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.使用 grpc_tools 我得到了类,现在,当我尝试从 py 客户端发送请求时,但在“stub.NodeConfig()”调用中捕获了错误 Even If I call it like "stub.NodeConfig({})" or "stub.NodeConfig("")" I have the same TypeError.即使我将其称为“stub.NodeConfig({})”或“stub.NodeConfig("")”,我也有相同的 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"

Solution :解决方案

  empty = node_info_service_pb2.google_dot_protobuf_dot_empty__pb2.Empty()
  response = stub.NodeConfig(empty)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 3-Google protobuf响应-不带.proto文件的解码 - Python 3 - Google protobuf response - decode without .proto file 在python中使用google的protobuf而不安装它 - Using google's protobuf in python without installing it python protobuf为google proto的任何字段分配一个字典 - python protobuf assign a dictionary to any fields of google proto 将Python生成的protobuf转换为不带.proto文件的java - Convert Python generated protobuf to java without .proto file TypeError:并非使用MySQL和Python在字符串格式化期间转换所有参数 - TypeError: not all arguments converted during string formatting using MySQL and Python python:在拦截器中读取grpc proto请求 - python: read grpc proto request in interceptor Python 没有 arguments 的 OPC UA 调用方法给出错误 - Python OPC UA call method without arguments gives error python 3函数检查数字是否奇怪使用%,给我错误:TypeError:并非所有参数在字符串格式化期间转换 - python 3 function to check if numbers are odd using %, giving me error: TypeError: not all arguments converted during string formatting 使用 Sublime TEXT 的 PYTHON 新手“TypeError:并非所有参数都在字符串格式化期间转换”适用于所有其他查询,但此 - New to PYTHON using Sublime TEXT“TypeError: not all arguments converted during string formatting” works on all other queries but this 不能使用python将字符串与.join连接在一起。 TypeError:在字符串格式化期间并非所有参数都已转换 - can't concatenate string with .join using python. TypeError: not all arguments converted during string formatting
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM