gpt4 book ai didi

python - 使用 google/protobuf/empty.proto 在没有参数的情况下调用 python grpc 方法期间出现 TypeError

转载 作者:行者123 更新时间:2023-12-05 01:32:54 47 4
gpt4 key购买 nike

我有一个这样的原型(prototype)方案:

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

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

使用 grpc_tools 我得到了类,现在,当我尝试从 py 客户端发送请求时,但在“stub.NodeConfig()” 调用中捕获了错误。即使我将其称为“stub.NodeConfig({})”或“stub.NodeConfig("")”,我也会遇到相同的 TypeError。客户端完整代码:

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: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"

最佳答案

解决方案:

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

关于python - 使用 google/protobuf/empty.proto 在没有参数的情况下调用 python grpc 方法期间出现 TypeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65127716/

47 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com