Gurkmeja101
Gurkmeja101

Reputation: 662

grpc client dns resolution failed when trying to access grpc server on same network

I'm trying to call a GRPC server running on a .Net Core project from a Python client.

When running against localhost:5001 it works fine, but running against the actual IP of the machine from within the same network like 192.168.1.230:5001 it doesn't work and I get an error DNS resolution failed.

I've downloaded the SSL cert and am at the moment reading it as a file from the client. It works when running against localhost so I don't think that is the problem.

Is there a better way to do this kind of testing of having clients run on separate devices but on the same network as the server? Hosting the GRPC server outside during development doesn't really seem like the best solution.

Python code:

import grpc
import datamessage_pb2 as datamessage
import datamessage_pb2_grpc as datamessageService


def main():
    print("Calling grpc server")
    with open("localhost.cer", "rb") as file:
        cert = file.read()
    credentials = grpc.ssl_channel_credentials(cert)
    channel = grpc.secure_channel("https://192.168.1.230:5001", credentials)
    # channel = grpc.secure_channel("localhost:5001", credentials)
    stub = datamessageService.StationDataHandlerStub(channel)
    request = datamessage.StationDataModel(
        temperature=22.3, humidity=13.3, soilMoisture=35.0)

    result = stub.RegisterNewStationData(request)
    print(result)


main()

Server settings in Program.cs:

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseUrls("https://*:5001");
                    webBuilder.UseStartup<Startup>();
                });

Settings in firewall: enter image description here

Traceback:

grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
        status = StatusCode.UNAVAILABLE
        details = "DNS resolution failed"
        debug_error_string = "{"created":"@1576101634.549000000","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3934,"referenced_errors":[{"created":"@1576101634.549000000","description":"Resolver transient failure","file":"src/core/ext/filters/client_channel/resolving_lb_policy.cc","file_line":262,"referenced_errors":[{"created":"@1576101634.549000000","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":"@1576101634.549000000","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}]}]}]}"

Upvotes: 5

Views: 14949

Answers (1)

Kanhaiya P. Baranwal
Kanhaiya P. Baranwal

Reputation: 111

In Python gRPC client, calling channel without protocol (https:) is required. So, I called gRPC service in dotnet core framework with following and it worked. Note, dotnet gRPC server was listening on https://localhost:5001.

with open('localhost.crt', 'rb') as f:
    credentials = grpc.ssl_channel_credentials(f.read())
with grpc.secure_channel('localhost:5001', credentials) as channel:
    stub = pb2_grpc.GreeterStub(channel)
    request = pb2.HelloRequest(name = "GreeterPythonClient")
    response = stub.SayHello(request)

Upvotes: 3

Related Questions