Skip to content
Latchkey

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 failed

Common 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

  1. Confirm the base URL and port match the CI service.
  2. Use an httpx transport with retries, or wrap the call in a backoff loop.
  3. 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →