# Use a proxy with Python HTTPX

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

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.

html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}
