Python "httpx.ConnectError" in CI
httpx.ConnectError: All connection attempts failed is raised when httpx exhausts its connection attempts to the target without success, the async/HTTP/2-aware equivalent of a requests ConnectionError.
What this error means
An httpx call fails with "httpx.ConnectError: All connection attempts failed" against a local or remote service.
python
httpx.ConnectError: All connection attempts failedCommon causes
The target service is not accepting connections
A dependency is down or not yet listening when the request runs.
Wrong base URL or port in the CI environment
The configured endpoint does not match where the service runs on the runner.
How to fix it
Verify the endpoint and add bounded retries
- Confirm the base URL and port match the CI service.
- Use an httpx transport with retries, or wrap the call in a backoff loop.
- In unit tests, use httpx MockTransport instead of real connections.
Python
import httpx
transport = httpx.HTTPTransport(retries=3)
client = httpx.Client(transport=transport, base_url="http://api:8000")How to prevent it
- Latchkey managed runners auto-retry transient connection failures while dependent services start.
- Use MockTransport in unit tests for deterministic behavior.
- Gate integration calls on a readiness check.
Related guides
Python "requests.exceptions.ConnectionError: Max retries exceeded" in CIFix "requests.exceptions.ConnectionError: Max retries exceeded with url" in CI - requests could not establish…
Python "aiohttp.ClientConnectorError" in CIFix "aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host" in CI - the aiohttp client could…
Python "urllib3 NewConnectionError" in CIFix "urllib3.exceptions.NewConnectionError: Failed to establish a new connection" in CI - urllib3 could not o…