# aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host example.com:80 ssl:default [Connection refused]

- **ID:** `python/aiohttp-client-connector-connection-error`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The remote host actively refused the connection, either because no service is listening on that port or a firewall blocked it.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.10 | active | — | — |
| 3.11 | active | — | — |

## Workarounds

1. **Check if the service is running and the port is open** (80% success)
   ```
   import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('example.com', 80))
if result != 0:
    print('Port is closed')
   ```
2. **Use a fallback URL or service discovery** (75% success)
   ```
   try:
    async with session.get('http://example.com') as resp:
        pass
except aiohttp.ClientConnectorError:
    async with session.get('http://backup.example.com') as resp:
   ```

## Dead Ends

- **Retrying with the same parameters indefinitely** — If the service is down, retrying won't help and may waste resources. (50% fail)
- **Changing the port to a common alternative without verification** — The service may not be running on the alternative port either. (60% fail)
