Using Proxies with Python, Go, and Node.js
These examples show the basic client configuration for an HTTP proxy. Store endpoints and API keys outside source code, set timeouts, and handle failures explicitly.
Python with Requests
import os
import requests
proxy = os.environ["HTTP_PROXY_URL"]
proxies = {"http": proxy, "https": proxy}
response = requests.get(
"https://example.com/",
proxies=proxies,
timeout=(5, 15),
)
response.raise_for_status()
print(response.status_code)
Use a requests.Session when multiple calls share cookies. Replace the proxy only between independent sessions or after a confirmed network failure.
Go with net/http
proxyURL, err := url.Parse(os.Getenv("HTTP_PROXY_URL"))
if err != nil {
log.Fatal(err)
}
client := &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)},
Timeout: 15 * time.Second,
}
resp, err := client.Get("https://example.com/")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
fmt.Println(resp.StatusCode)
Reuse the http.Client and transport for requests using the same proxy. Creating a new transport for every request prevents effective connection reuse.
Node.js with fetch and an agent
import { ProxyAgent } from "undici";
const dispatcher = new ProxyAgent(process.env.HTTP_PROXY_URL);
const response = await fetch("https://example.com/", {
dispatcher,
signal: AbortSignal.timeout(15000),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(response.status);
Use the proxy-agent mechanism supported by your selected HTTP client. Client options differ, so verify behavior against the exact library version in your application.
Retrieve endpoints from the API
Fetch endpoints over HTTPS using the API key from an environment variable, parse the documented response, then pass one selected proxy into the client configuration above. Consult the live API documentation for the current endpoint and response shape.
Production checklist
- Never commit API keys or authenticated proxy URLs.
- Set connect and overall timeouts.
- Use bounded retries only for suitable operations.
- Validate TLS certificates; do not disable verification.
- Log endpoint IDs or masked addresses instead of credentials.
Get API-ready proxies
Use the IPPool API to supply recently checked endpoints to your application.
View plansOpen API documentation