我已经在.NET中成功地制作了一个Grpc服务器和客户端。我正在尝试从Python重新创建客户端。在.NET中,我必须创建这些channelOptions,以避免返回SSL错误。我无法在Python中复制这些选项。我已经尝试使用channel = grpc.insecure_channel('127.0.0.1:5001')
并收到相同的状态代码,它是不可用的。尽管存在该错误,但我可以正常运行.NET客户端。
我使用$ python -m grpc_tools.protoc -I../../protos --python_out=. --pyi_out=. --grpc_python_out=. ../../protos/route_guide.proto
pb2.py从.NET应用程序中的proto文件填充www.example.com和pb2_grpc.py文件。我是否需要使用指定Python客户端的语法构建.proto文件?
//.NET
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
};
var channelOptions = new GrpcChannelOptions
{
HttpHandler = handler
};
var channel = GrpcChannel.ForAddress("https://127.0.0.1:5001",channelOptions);
//Python
options = [('grpc.ssl_target_name_override', '127.0.0.1')]
creds = grpc.ssl_channel_credentials()
channel = grpc.secure_channel("127.0.0.1:5001", creds, options)
//错误
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "failed to connect to all addresses;
last error: UNKNOWN: ipv4:127.0.0.1:5001:
Ssl handshake failed: SSL_ERROR_SSL:
error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED"
debug_error_string = "UNKNOWN:failed to connect to all addresses;
last error: UNKNOWN: ipv4:127.0.0.1:5001: Ssl handshake failed:
SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED
1条答案
按热度按时间8nuwlpux1#
想明白了我需要在appsettings.json中指定“Http2”协议。
这是我的示例repo。https://github.com/ifTaylor/grpc_pynet