I am currently trying to get an example for gRPC working. I am using a C# Asp.NET Core WebApi as the server and I try to connect to it via a Python client.
Ressources
My proto file:
syntax = "proto3";
service Example {
rpc Insert (InsertRequest) returns (Empty);
rpc Update (UpdateRequest) returns (Empty);
rpc Delete (DeleteRequest) returns (Empty);
}
message InsertRequest {
int32 Value = 1;
}
message UpdateRequest {
string Id = 1;
int32 Value = 2;
}
message DeleteRequest {
string Id = 1;
}
message Empty { }
The Python Client:
import grpc
import example_pb2
import example_pb2_grpc
with grpc.insecure_channel('localhost:5001') as channel:
stub = example_pb2_grpc.ExampleStub(channel)
stub.Insert(example_pb2.InsertRequest(Value = 155))
Problem
When I try to run my Python client I get the following error:
Traceback (most recent call last): File "gRPCExampleClient.py", line 10, in stub.Insert(example_pb2.InsertRequest(Value = 155)) File "C:\Python38\lib\site-packages\grpc_channel.py", line 923, in call return _end_unary_response_blocking(state, call, False, None) File "C:\Python38\lib\site-packages\grpc_channel.py", line 826, in _end_unary_response_blocking raise _InactiveRpcError(state) grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNAVAILABLE details = "failed to connect to all addresses" debug_error_string = "{"created":"@1612810257.299000000","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":5391,"referenced_errors":[{"created":"@1612810257.299000000","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":398,"grpc_status":14}]}"
What I tried so far
- Explicitly enable HTTP/2 for my Kestrel server
- Verified the server is working with a C# gRPC client
- The C# client uses the same proto file as the Python client (C# client works just as expected and can communicate with the server)
class Program
{
static void Main(string[] args)
{
var channel = GrpcChannel.ForAddress("https://localhost:5001");
var client = new Example.ExampleClient(channel);
client.Insert(new InsertRequest() { Value = 155 });
Console.ReadKey(true);
}
}
- Tried to use "https://" scheme in my Python client (
with grpc.insecure_channel('https://localhost:5001') as channel:
). When doing this I get the following error message:
Traceback (most recent call last): File "gRPCExampleClient.py", line 10, in stub.Insert(example_pb2.InsertRequest(Value = 155)) File "C:\Python38\lib\site-packages\grpc_channel.py", line 923, in call return _end_unary_response_blocking(state, call, False, None) File "C:\Python38\lib\site-packages\grpc_channel.py", line 826, in _end_unary_response_blocking raise _InactiveRpcError(state) grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNAVAILABLE details = "DNS resolution failed for service: https://localhost:5001" debug_error_string = "{"created":"@1612809227.889000000","description":"Resolver transient failure","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":2141,"referenced_errors":[{"created":"@1612809227.889000000","description":"DNS resolution failed for service: https://localhost:5001","file":"src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc","file_line":201,"grpc_status":14,"referenced_errors":[{"created":"@1612809227.889000000","description":"OS Error","file":"src/core/lib/iomgr/resolve_address_windows.cc","file_line":95,"os_error":"No such host is known.\r\n","syscall":"getaddrinfo","wsa_error":11001}]}]}"
- After this, I tried to set the environment variable
GRPC_DNS_RESOLVER
tonative
. Sadly the error stayed the same
from os import environ
environ["GRPC_DNS_RESOLVER"] = "native"
- Tried using
127.0.0.1
,0.0.0.0
with and withouthttps://
scheme instead oflocalhost
Misc infos
- According to https://github.com/grpc/grpc-dotnet/issues/959#issuecomment-647935019 when not specifying any scheme gRPC prepends
dns://
as a default. I was able to confirm this by enablingenviron["GRPC_TRACE"] = "api,client_channel_routing,cares_resolver"
andenviron["GRPC_VERBOSITY"] = "debug"
- -> This makes it seem like the DNS error which occurs when specifying
https
is the one that I should focus on resolving sincedns://
might be resolvable but doesn't make any sense in the first place. - Sadly this https://stackoverflow.com/a/62136381/4932122 seems to contradict this assumption
- -> This makes it seem like the DNS error which occurs when specifying
I hope I am just missing something obvious thanks for reading and considering to help.