Skip to content

Python integration ​

Send requests through an assigned static endpoint. The example reads credentials from the process environment and uses an HTTP proxy for an HTTPS target by default. It does not fetch or rotate IPs.

Before you start ​

Set PROXY_HOST, PROXY_PORT, PROXY_USERNAME, and PROXY_PASSWORD in the terminal, container, or deployment platform running the program. Use the current dashboard details and the port for the selected protocol. Keep actual passwords out of source control, logs, and frontend code.

Runtime and dependencies ​

Use Python 3 and requests with SOCKS support. Save the sample as proxy_example.py.

sh
python -m pip install "requests[socks]"
python proxy_example.py

Set up the connection ​

python
import os
from urllib.parse import quote
import requests

host = os.environ["PROXY_HOST"].strip("[]")
port = int(os.environ["PROXY_PORT"])
user = quote(os.environ["PROXY_USERNAME"], safe="")
password = quote(os.environ["PROXY_PASSWORD"], safe="")
scheme = os.environ.get("PROXY_SCHEME", "http")
if scheme not in {"http", "socks5h"}:
    raise ValueError("PROXY_SCHEME must be http or socks5h")
host = f"[{host}]" if ":" in host else host
proxy_url = f"{scheme}://{user}:{password}@{host}:{port}"

try:
    with requests.Session() as session:
        session.trust_env = False
        session.proxies = {"http": proxy_url, "https": proxy_url}
        response = session.get("https://ip123.in/ip.json", timeout=(10, 30))
        response.raise_for_status()
        print(response.json())
except requests.RequestException as error:
    raise SystemExit(f"Proxy request failed: {type(error).__name__}") from None

PROXY_SCHEME defaults to http. For SOCKS5, set it to socks5h and use the matching SOCKS5 port so the target hostname is resolved remotely. Switching protocols does not rotate the assigned static exit.

If something goes wrong ​

If this example succeeds but your workload fails, check the actual request process, SDK proxy configuration, timeouts, and retry policy. Keep TLS certificate verification enabled. The sample prints lookup data or errors without credentials; redact diagnostic logs too. See the FAQ.