Python not able to connect to grpc channel

Viewed 46

I have a problem with my server and client in my grpc channel, the server:

import logging
import grpc
import sys
sys.path.append("proto")
import proto.nvidia_pb2_grpc
from servicer import NvidiaServicer


GRPC_PORT = '50057'
socket = "localhost:{0}".format(GRPC_PORT)

def server():
    logger.info('Setting up gRPC server')
    grpc_server = grpc.server(concurrent.futures.ThreadPoolExecutor(max_workers=10))
    proto.nvidia_pb2_grpc.add_NvidiaServicer_to_server(
        NvidiaServicer(), grpc_server
    )
    
    logger.info(f'Starting server at {socket}')
    grpc_server.add_insecure_port(socket)
    grpc_server.start()

the following servicer:

import proto.nvidia_pb2
import proto.nvidia_pb2_grpc
import logging
from driver_status import checkDriverStatus
logger = logging.getLogger()

class NvidiaServicer(proto.nvidia_pb2_grpc.NvidiaServicer):
    def NvidiaDriverStatus(self, request, context):
        logger.info('######################################################')
        logger.info('gRPC server got request to check driver status')
        response = proto.nvidia_pb2.DriverStatus()
        result = checkDriverStatus()

        response.status.value = result
        return response
    

and from the client side this is my client from asyncio.log import logger import grpc import os from proto import nvidia_pb2 from proto import nvidia_pb2_grpc

GRPC_PORT = '50057'
socket = 'localhost:{}'.format(GRPC_PORT)

def GrpcClientNvidia():
    try:
        if os.environ.get('https_proxy'):
            del os.environ['https_proxy']
        if os.environ.get('http_proxy'):
            del os.environ['http_proxy']
        channel = grpc.insecure_channel(socket, options=(('grpc.enable_http_proxy', 0),))
        stub = nvidia_pb2_grpc.NvidiaStub(channel)
        res = stub.NvidiaDriverStatus(nvidia_pb2.Empty())
        return res.status.value
    except grpc.FutureTimeoutError:
         logger.error('Error connecting to nvidia server')

But whenever I run my main I still am getting

File "/usr/local/lib/python3.6/site-packages/grpc/_channel.py", line 849, 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":"@1661349318.910632939","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3260,"referenced_errors":[{"created":"@1661349318.910631609","description":"failed to connect to all addresses","file":"src/core/lib/transport/error_utils.cc","file_line":167,"grpc_status":14}]}"

my main:

from GrpcClientNvidia import GrpcClientNvidia
result = {}
result['SW'] = {}
result['SW']['nvidia'] = runNvidiaDriverCheck()

def runNvidiaDriverCheck():
    return GrpcClientNvidia()

What am I doing wrong?

1 Answers

I needed to change localhost into 127.0.0.1

Related