第一步:安装依赖包
googleapis-common-protos==1.54.0
grpcio==1.42.0
grpcio-tools==1.42.0
protobuf==3.19.1
six==1.16.0
pip3.9 install grpcio pip3.9 install grpcio-tools pip install googleapis-common-protos
第二步:写client
# coding=utf-8
ixxxort json
ixxxort grpc
from x'x'x ixxxort xxx_pb2_grpc, xxx_pb2
def run():
# 连接rpc服务器,insecure(不安全的)
"""
'xxx-xxx-grpc.xxx.test:xxx' 为服务端起的端口
"""
channel = grpc.insecure_channel('xxx-xxx-grpc.xxx.test:xxx')
# 调用rpc服务
"""
SecurityStub就是生成的xxx_pb2_grpc.py中的类class SecurityStub(object),
而Security就是grpc协议文档xxx.proto中的service Security,然后拼接成SecurityStub
stub.xxx就是xxx.proto中的rpc xxx,
xxx_pb2.RequestSecurity就是 rpc xxx(RequestSecurity)中的请求"RequestSecurity",
参数就是app_id=12345678就是 uint32 app_id = 1 定义的参数名app_id,
response获取响应的结果 xxx.proto的message ResponseSecurity
"""
stub = xxx_pb2_grpc.SecurityStub(channel)
request_data = xxx_pb2.RequestSecurity(xxx =12345678, xxx ="小米")
print(

本文介绍了如何在Python3环境下,通过安装必要的依赖包(如googleapis-common-protos, grpcio等),创建客户端并进行GRPC调用到Go语言实现的服务端。步骤包括安装依赖和编写及运行客户端代码。"
78291217,5656766,PHP实现POST方式采集网页数据教程,"['PHP实战', 'PHP采集', 'PHP爬虫', 'post采集']
最低0.47元/天 解锁文章
2732

被折叠的 条评论
为什么被折叠?



