diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/resolver.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/resolver.pyx.pxi index 4c102392e5c..d533d6e3a37 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/resolver.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/resolver.pyx.pxi @@ -35,6 +35,7 @@ cdef class _AsyncioResolver: res = future.result() except Exception as e: error = True + error_msg = str(e) finally: self._task_resolve = None @@ -48,7 +49,7 @@ cdef class _AsyncioResolver: grpc_custom_resolve_callback( self._grpc_resolver, NULL, - grpc_socket_error("getaddrinfo {}".format(str(e)).encode()) + grpc_socket_error("getaddrinfo {}".format(error_msg).encode()) ) cdef void resolve(self, char* host, char* port): diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/socket.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/socket.pyx.pxi index 690c34c2da9..ebe6bee8316 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/socket.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/socket.pyx.pxi @@ -45,6 +45,7 @@ cdef class _AsyncioSocket: self._reader, self._writer = future.result() except Exception as e: error = True + error_msg = str(e) finally: self._task_connect = None @@ -61,7 +62,7 @@ cdef class _AsyncioSocket: else: self._grpc_connect_cb( self._grpc_socket, - grpc_socket_error("connect {}".format(str(e)).encode()) + grpc_socket_error("connect {}".format(error_msg).encode()) ) def _read_cb(self, future):