【问题标题】:In python grpc I got a exception “No match found for server name”在 python grpc 中,我得到一个异常“找不到服务器名称的匹配项”
【发布时间】:2017-06-29 02:48:41
【问题描述】:

我用这个命令创建密钥:

openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.crt

我的服务器代码:

server_credentials = grpc.ssl_server_credentials(((_private_key, _certificate_chain,),))

server = grpc.server(futures.ThreadPoolExecutor(max_workers=MAX_THREADPOOL_EXECUTOR))
server.add_secure_port('[::]:{0}'.format(AGENT_PORT), server_credentials)
server.add_insecure_port('[::]:{0}'.format(AGENT_PORT))

print("AgentServicer start at port {}...".format(AGENT_PORT))
server.start()
try:
    while True:
        # we can do something in main thread......
        time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
    server.stop(0)

我的客户代码:

credentials = grpc.ssl_channel_credentials(root_certificates=_certificate_chain)
channel = grpc.secure_channel('{}:{}'.format("localhost", 10010), credentials)

# channel = grpc.insecure_channel('{}:{}'.format("localhost", 10010))
stub = agent_pb2_grpc.AgentStub(channel)
response = stub.GetAgentVersion(agent_pb2.NoParams())
print("GreeterService client received: " + response.version)

我得到一个例外:

No match found for server name

我做错了什么?

【问题讨论】:

    标签: python grpc


    【解决方案1】:

    我怀疑您的服务器证书没有您尝试从客户端连接的CN=localhost。在这种情况下,您需要创建服务器证书以包含此类 Common Name,或者从您的客户端连接到证书中存在的名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-31
      • 2018-05-09
      • 2016-12-09
      • 2011-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-13
      相关资源
      最近更新 更多