Use proxy= when one endpoint should handle the client's requests. Use mounts= when destination schemes need different routes. These examples use those HTTPX interfaces; a project using the older proxies= API needs configuration matching that version.

One endpoint

import httpx

timeout = httpx.Timeout(15.0, connect=5.0)

with httpx.Client(
    proxy="http://127.0.0.1:8080",
    trust_env=False,
    timeout=timeout,
) as client:
    response = client.get("https://example.com/")
    response.raise_for_status()
    print(response.status_code)

Replace the local listener with a running HTTP proxy; a candidate from the HTTP proxy list still needs testing against your destination. An HTTPS target can use this http:// endpoint through CONNECT. Changing the endpoint scheme to https:// instead requests TLS to the proxy, which needs support from both listener and client.

Separate routes by destination scheme

import httpx

mounts = {
    "http://": httpx.HTTPTransport(
        proxy="http://127.0.0.1:8080",
        trust_env=False,
    ),
    "https://": httpx.HTTPTransport(
        proxy="http://127.0.0.1:8081",
        trust_env=False,
    ),
}

with httpx.Client(
    mounts=mounts,
    trust_env=False,
    timeout=httpx.Timeout(15.0, connect=5.0),
) as client:
    response = client.get("https://example.com/")
    response.raise_for_status()
    print(response.status_code)

Mount keys match target URLs. HTTP targets select port 8080 here; HTTPS targets select port 8081. The proxy value describes the listener's own protocol, so the HTTPS mount can correctly contain an http:// proxy. Substitute your endpoints and check both destination schemes.

Both recipes set trust_env=False on the client and, where supplied, the transports. HTTPX otherwise reads proxy and certificate environment variables by default. If your deployment relies on those variables, keep discovery enabled or configure the required routes and trust explicitly. Use the TLS context and CA configuration supported by your HTTPX version for private trust; leave destination verification enabled. HTTPS proxy trust can be separate from destination trust.

httpx.Timeout(15.0, connect=5.0) overrides connection timeout behavior while supplying the other configured timeout components from the default. Read, write and pool waiting have separate limits; fifteen seconds is not a total wall-clock deadline. A pool timeout can mean other work holds the available connections. Close clients and streaming responses correctly before treating it as evidence that the proxy is unreachable.

འབྲེལ་བའི་རྩོམ་ཡིག