我有一个用 Python 编写的 GRPc 服务器,我刚刚实现了 TSL 加密。
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
test_pb2_grpc.add_TestServicer_to_server(TestServicer(), server)
with open(SERVER_PRIVATE_KEY, 'rb') as f:
private_key = f.read()
with open(SERVER_CERTIFICATE, 'rb') as f2:
certificate_chain = f2.read()
server_credentials = grpc.ssl_server_credentials(((private_key, certificate_chain,),))
server.add_secure_port('[::]:{}'.format(SERVER_PORT), server_credentials)
server.start()
如果我尝试在没有证书的情况下连接
with grpc.insecure_channel(target='localhost:50051') as channel:
stub = test_pb2_grpc.TestStub(channel)
guide_get_one_feature(stub, Test_pb2.UserInfo("test"))
我在服务器上收到此错误
E0712 14:30:29.748944000 123145353949184 ssl_transport_security.cc:1238] Handshake failed with fatal error SSL_ERROR_SSL: error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER.
我已经将记录器设置为写入文件
logger = logging.getLogger(name)
filename = datetime.datetime.now().strftime("%Y-%m-%d")
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.FileHandler("{}.log".format(filename)))
但我无法记录 grpc 错误。有没有办法以某种方式处理这些错误?