Proxy Setup for Python, Node.js and Docker

HTTPX Proxy Setup for Python: Auth and Async

Configure an HTTPX proxy with authentication, fix the removed proxies argument, use AsyncClient, and check environment settings with tested Python examples.

By Proxies.sx Team. Reviewed .

Pass proxy= when you create the HTTPX client. Put proxy credentials on httpx.Proxy, keep TLS verification enabled, and use the same client for the requests that should share its configuration.

In this guide

Make one authenticated HTTPS request

This example targets HTTPX 0.28.1. Install it in your project environment with python -m pip install "httpx==0.28.1". Set PROXY_SERVER to the provider's scheme, host and port; supply the raw username and password in the two separate environment variables. The configuration hub explains those inputs.

The default target returns a JSON IP observation. You can replace TARGET_URL with a JSON endpoint you control. A successful response confirms that request; verify the content your real application needs next.

import os
import ssl
import httpx

# Use raw credentials here, not percent-encoded URL components.
proxy = httpx.Proxy(
    os.environ["PROXY_SERVER"],
    auth=(os.environ["PROXY_USERNAME"], os.environ["PROXY_PASSWORD"]),
)
tls = ssl.create_default_context(cafile=os.environ.get("PROXY_TEST_CA"))
target = os.environ.get("TARGET_URL", "https://api.ipify.org?format=json")

try:
    with httpx.Client(
        proxy=proxy,
        trust_env=False,
        verify=tls,
        timeout=httpx.Timeout(15.0, connect=5.0),
        follow_redirects=False,
    ) as client:
        response = client.get(target)
        response.raise_for_status()
        print(response.json())
except httpx.HTTPError as error:
    # Do not print a full proxy URL or exception traceback with credentials.
    print("Request failed:", type(error).__name__)
    raise SystemExit(1)
Download the complete example

Fix the proxies argument error

HTTPX removed the deprecated proxies argument in 0.28.0. For one proxy, replace Client(proxies=...) with Client(proxy=...). A Requests-style dictionary is not a drop-in value for that singular argument.

Configure an existing client's proxy at construction. The top-level httpx.get(..., proxy=...) function is a different API from client.get(...). For different routes by URL pattern, review HTTPX's transport mounts rather than passing a new proxy to each client method.

If a dependency still supplies proxies=, changing your own call may leave its failing call untouched. Identify the package named in the traceback, check its supported HTTPX versions, and update the dependency or its compatible lockfile together.

Keep proxy configuration on the async client

The same proxy object can configure an AsyncClient. Reuse the client for a batch and await each request, or use bounded concurrency appropriate to your application. Creating a client inside every iteration discards the benefit of connection pooling. HTTPX describes client lifetime in its async guide.

Use asyncio.run(main()) in a script. In an environment that already runs an event loop, call await main() through that environment's supported entry point.

The fragment below reuses proxy, tls and target from the first example. The download includes those definitions and error handling.

import asyncio

async def main():
    async with httpx.AsyncClient(
        proxy=proxy, trust_env=False, verify=tls,
        timeout=httpx.Timeout(15.0, connect=5.0),
    ) as client:
        response = await client.get(target)
        response.raise_for_status()
        print(response.json())

asyncio.run(main())
Download the complete example

Separate explicit routing, environment settings and timeouts

HTTPX uses environment settings by default. The example deliberately sets trust_env=False and supplies its proxy directly. When testing an environment-based setup, remove the explicit proxy and inspect HTTP_PROXY, HTTPS_PROXY, ALL_PROXY and NO_PROXY as described in the HTTPX environment reference.

HTTPS_PROXY selects a route for an HTTPS destination. Its value can still begin with http:// when the proxy accepts an HTTP CONNECT request. Match the proxy scheme to the provider's listener.

httpx.Timeout(15.0, connect=5.0) sets operation timeouts; it does not impose a single 15-second deadline on the whole job. The timeout reference distinguishes connect, read, write and pool waits. If the application needs a total deadline, implement it at the job level.

The example constructs its TLS context explicitly. Leave PROXY_TEST_CA unset for the system trust store, or point it to an approved CA bundle when your environment requires one. Avoid replacing a certificate failure with verify=False.

What we checked locally

We ran both downloadable examples through an authenticated local HTTP proxy to a local HTTPS origin. The proxy recorded a CONNECT tunnel, the destination received no proxy authorization header, and incorrect credentials stopped the request. A separate environment test used the proxy by default and bypassed it when NO_PROXY matched the destination IP.

The test record names the exact versions and checks. These observations establish the example's behavior in that fixture. They do not measure public exit IPs, SOCKS support, target acceptance or Proxies.sx performance.

For SOCKS, HTTPX documents the optional httpx[socks] dependency. Check the provider's scheme and the client's DNS behavior before switching protocols. Continue to the SOCKS DNS guide if hostname resolution is the issue.

Common questions

Where do I put the proxy password?

On the proxy configuration, separate from destination authentication. The example passes raw credentials to httpx.Proxy and does not use the destination auth argument.

Will AsyncClient rotate the IP for each request?

Async execution does not define proxy rotation. Session tokens, gateway behavior and reused connections affect routing. Use the username builder and test the actual connection pattern.

Sources and test scope

Official documentation checked on 14 October 2026. The linked local test records identify the tested versions and limits. The examples do not establish public proxy availability or destination acceptance.

Machine-readable guide index and local routing test results.

Connect your application to Proxies.sx

Use the username builder for gateway routing fields and the format converter for existing connection lists. Review Pool Gateway documentation, then check current mobile stock before buying traffic.

For agent-driven workflows, the agent service index lists the supported APIs. A configured HTTP client still needs to validate its task's response.

Configure the client that sends your requests

Start with the proxy configuration guide, or open the setup for your runtime.