Built-in Exceptions

ConnectionRefusedError — exception class

A connection attempt was refused, commonly because no service accepts connections at the target. Verify endpoint and service readiness before a bounded retry. The example uses the symbolic errno.ECONNREFUSED to demonstrate CPython exception selection without accessing an external system. The example raises a controlled stand-in to demonstrate handling; it does not cause the real system failure. Catch ConnectionRefusedError when this category is the recovery boundary; do not rely on the exact human-readable message.

Formal Syntax & Structure

python syntaxpython
ConnectionRefusedError

Return Value

type

The class object ConnectionRefusedError; this reference documents the class identity, not a universal constructor signature.

Working Example

Example Snippetpython
import errnotry:    raise OSError(errno.ECONNREFUSED,"demo")except ConnectionRefusedError as error:    print(type(error).__name__)
Python Reference