import asyncio
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")

async def main():
    try:
        async with httpx.AsyncClient(
            proxy=proxy,
            trust_env=False,
            verify=tls,
            timeout=httpx.Timeout(15.0, connect=5.0),
            follow_redirects=False,
        ) as client:
            response = await client.get(target)
            response.raise_for_status()
            print(response.json())
    except httpx.HTTPError as error:
        print("Request failed:", type(error).__name__)
        raise SystemExit(1)

asyncio.run(main())
