Skip to main content
The Center's Directory
Code examples

Use a proxy with Python HTTPX

Synchronization agent requests are completed using HTTPX Client, accounting environment variables, and tiering timeouts.

Maintained by the ZZHTTP engineering teamUpdated September 20, 2026

HTTPX is suitable for synchronization services and Python projects that need to connect to pools. HTTPS targets still establish CONNECT tunnels through HTTP proxy URLs, and the accounting network is closed to us.zzhttp.com:7878.

Precondition

  • Caller project installs and locks itself httpx.
  • Get the current full proxy username and sub-username and password from the console.
  • Injection through controlled environment PROXY_USERNAME and PROXY_PASSWORD.

Complete example

Python
import os
from urllib.parse import quote

import httpx

proxy_username = quote(os.environ["PROXY_USERNAME"], safe="")
proxy_password = quote(os.environ["PROXY_PASSWORD"], safe="")
proxy_url = (
    f"http://{proxy_username}:{proxy_password}"
    "@us.zzhttp.com:7878"
)
timeout = httpx.Timeout(30.0, connect=10.0)

with httpx.Client(proxy=proxy_url, timeout=timeout) as client:
    response = client.get("https://ipinfo.io/json")
    response.raise_for_status()
    print(response.json())

Expected results

  • The request returns a successful status and displays the proxy exit IP.
  • In response ip is the export address,country and region (a) Can be used for initial verification of areas. There may be deviations in the positioning of third-party databases.
  • The same one. Client Reusable connections, not creating a client for each request.

Error handling

  • When you receive a 407, first check your full username, password, and current subscription rights.
  • ConnectTimeout Indicates that the proxy connection phase has timeout,ReadTimeout Indicates a timeout while waiting for the target to respond.
  • Only limited retry avoidance is performed for safely replayable requests.

Safety tips

Don't record. proxy_url The full proxy information in the request header or exception object. The log only retains the task ID, target host, error type, and desensitized requestId.

Did this answer your question?

Feedback is used only to improve the public documentation and does not submit accounts or request information.