Search code examples
pythongrpcgrpc-python

python grpc DNS resolution failed


I have been attempting to connect to a gRPC server hosted behind the domain name "example.com/server".

I am using grpc.secure_channel to establish the connection. However, I encounter the error message DNS resolution failed for example.com/server: UNKNOWN: Name or service not known. Interestingly, if I change the domain name to just "example.com", the connection works fine. It seems that the GRPC_DNS_RESOLVER is unable to resolve domain names that include a directory path after the hostname.

Has anyone encountered this issue before or have any suggestions on how to resolve it?

channel_credential = grpc.ssl_channel_credentials(crt.encode())
channel = grpc.secure_channel('example.com/server', channel_credential)
intercept_channel = grpc.intercept_channel(channel)
stub = project_pb2_grpc.MyStub(intercept_channel)
stub.task()

Solution

  • gRPC does not use paths, you should only provide the server name.