gRPC HelloWorld-从Python客户端向ASP.NET核心服务器发送消息时出错

gRPC HelloWorld-从Python客户端向ASP.NET核心服务器发送消息时出错,python,asp.net-core,grpc,Python,Asp.net Core,Grpc,我使用以下命令设置了一个ASP.NET核心客户端 我的终点在 根据我在报纸上看到的,上面写着 “用于gRPC的Kestrel端点应使用TLS.In进行保护 在开发过程中,使用TLS保护的端点将在以下位置自动创建: 当ASP.NET核心开发证书 “存在” 在我的python代码中 """The Python implementation of the GRPC helloworld.Greeter client.""" from __future__ import print_function

我使用以下命令设置了一个ASP.NET核心客户端

我的终点在 根据我在报纸上看到的,上面写着

“用于gRPC的Kestrel端点应使用TLS.In进行保护 在开发过程中,使用TLS保护的端点将在以下位置自动创建: 当ASP.NET核心开发证书 “存在”

在我的python代码中

"""The Python implementation of the GRPC helloworld.Greeter client."""

from __future__ import print_function
import logging

import grpc

import greet_pb2
import greet_pb2_grpc


def run():
    # NOTE(gRPC Python Team): .close() is possible on a channel and should be
    # used in circumstances in which the with statement does not fit the needs
    # of the code.
    with grpc.insecure_channel('https://localhost:5001') as channel:
        stub = greet_pb2_grpc.GreeterStub(channel)
        response = stub.SayHello(greet_pb2.HelloRequest(name='you'))
    print("Greeter client received: " + response.message)


if __name__ == '__main__':
    logging.basicConfig()
    run()
但是当我运行它时,我得到了这个错误

Traceback (most recent call last):
  File "greet_client.py", line 37, in <module>
    run()
  File "greet_client.py", line 31, in run
    response = stub.SayHello(greet_pb2.HelloRequest(name='you'))
  File "D:\Anaconda\lib\site-packages\grpc\_channel.py", line 824, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "D:\Anaconda\lib\site-packages\grpc\_channel.py", line 726, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.UNAVAILABLE
        details = "DNS resolution failed"
        debug_error_string = "{"created":"@1580765368.309000000","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3941,"referenced_errors":[{"created":"@1580765368.309000000","description":"Resolver transient failure","file":"src/core/ext/filters/client_channel/resolving_lb_policy.cc","file_line":262,"referenced_errors":[{"created":"@1580765368.309000000","description":"DNS resolution failed","file":"src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc","file_line":202,"grpc_status":14,"referenced_errors":[{"created":"@1580765368.309000000","description":"OS Error","file":"src/core/lib/iomgr/resolve_address_windows.cc","file_line":96,"os_error":"No such host is known.\r\n","syscall":"getaddrinfo","wsa_error":11001}]}]}]}"
回溯(最近一次呼叫最后一次):
文件“greet_client.py”,第37行,在
运行()
文件“greet_client.py”,第31行,在运行中
response=stub.SayHello(greet_pb2.HelloRequest(name='you'))
文件“D:\Anaconda\lib\site packages\grpc\\ u channel.py”,第824行,在\uu调用中__
返回\u结束\u一元\u响应\u阻塞(状态、调用、错误、无)
文件“D:\Anaconda\lib\site packages\grpc\\u channel.py”,第726行,一元响应
raise\u InactiveRpcError(状态)

grpc.\u channel.\u inactiverpcerr:“没有已知的主机”错误很奇怪,因为本地主机通常很容易找到……我假设客户机和服务器在同一台机器上运行。您是否尝试连接到端口5000?根据,不安全的端口是5000,而不是5001。如果这无助于解决此问题,您能否验证您是否能够使用教程附带的ASP.NET客户端成功连接以帮助隔离问题?@EricG Yes当我在.NETCore(客户端和服务器)中运行所有内容时,就像在教程中一样,它工作正常,只是当我尝试从Python连接时。我认为这与TLS证书有关,也许我必须使用python的安全连接并创建自己的证书供双方使用-我认为.NET在调试时会自动生成它。根据aspnet文档,是服务器的TLS端口。因此,我希望您需要使用端口5000进行纯文本连接,但WSA 11001错误表明问题发生得更早,无法解决localhost。根据您使用的Windows环境,这可能是一个配置问题,例如,我能够找到。您可以尝试挖掘/etc/hosts文件,或者只是尝试一些localhost同义词,例如0.0.0.0:5000或127.0.0.1:5000