无法识别Pycharm中的Protobuf响应类型

bq8i3lrv  于 2023-08-05  发布在  PyCharm
关注(0)|答案(1)|浏览(192)

当我使用下面的代码时,我可以得到响应,并且它是有效的。响应类型正确。在PyCharm中,我希望能够键入“response.”,然后点击“ctrl+enter”,并看到“response.count”作为一个选项弹出。.pyi文件已生成,并且似乎具有适当的插槽。

with grpc.insecure_channel(‘localhost:4443’) as channel:
     stub = SERVICESgrpc.CountServiceStub(channel)
     response = stub.GetCount(SERVICES.CountRequest())
     print(type(response))
     #the above line prints that the type is a CountResponse - how do I make my IDE recognize that

字符串
我已经试着给予一个类型的响应与

with grpc.insecure_channel(‘localhost:4443’) as channel:
         stub = SERVICESgrpc.CountServiceStub(channel)
         response = SERVICES.CountResponse()
         #response.count autocompletes here
         response = stub.GetCount(SERVICES.CountRequest())
         #prints that the type is a CountResponse - how do I make my IDE recognize that
         print(type(response))
         #works, but will not auto-complete response.count
         print(response.count)


编辑:下面是grpc原型的编译过程

python -m grpc_tools.protoc -I../../../../googleapis -I../../protos --python_out=. --pyi_out=. --grpc_python_out=. ../../protos/mypackage/serviceapis.proto

xqkwcwgp

xqkwcwgp1#

Python模块grpc_tools.protoc使用的protoc版本稍旧。
您应该尝试直接使用二进制协议
参考:https://github.com/protocolbuffers/protobuf/issues/2638#issuecomment-1133604021

相关问题