# coding:utf-8 import grpc from proto import service_pb2, service_pb2_grpc def a2s_execute(a2s_ip: str, topic: str, timeout: int, bytes_data: bytes): """ a2e服务调用 :param a2s_ip: 192.168.3.240:9090 # 服务地址 :param topic: t2v 主体 :param timeout: 60 超时时间 :param bytes_data: 请求字段 :return: bytes or None """ try: if not (a2s_ip and topic): raise IOError("参数错误:a2s_ip和topic不能为空!") with grpc.insecure_channel(a2s_ip) as channel: # 客户端实例 stub = service_pb2_grpc.CallerStub(channel) print(topic,timeout,bytes_data) # 调用服务端方法 response = stub.Call(service_pb2.Request(topic=topic, timeout=timeout, data=bytes_data)) print("==>",response) # 获取结果 data = response.data return data except Exception as e: print(e) return None