Back to blog

Guide

How to Integrate Proxies Into Your Web Automation Workflow

How do you integrate proxies into a web automation workflow? Learn how to configure proxies in Python, Playwright, Puppeteer, and Selenium for reliable automation.

Integrating a proxy into a web automation workflow is technically straightforward — most automation tools support proxy configuration with a few lines of code. The part that requires more care is designing the integration so that proxy rotation, session management, and error handling work correctly at the scale and complexity your automation requires.

This guide covers proxy integration across the most common automation tools and patterns, along with the configuration decisions that affect whether the integration works reliably.

Understanding the Proxy Connection Model

Most residential and datacenter proxy providers expose a single gateway endpoint — a hostname and port — through which all proxy traffic routes. Your automation tool connects to this endpoint, passes credentials (typically via a username/password embedded in the proxy URL or via IP allowlisting), and the gateway assigns an IP from the pool and forwards traffic.

Targeting parameters — country, city, session ID, rotation behavior — are typically passed as additional elements in the username string. For example, a username like user-country-us-city-chicago-session-abc123 tells the gateway to assign a US Chicago IP and maintain it for the session identified as abc123.

This means your automation tool does not need to know about individual IPs — the gateway manages that. Your code only needs to connect to the gateway endpoint with the correct credentials and parameters.

Integration in Python with Requests

For HTTP-based automation using the requests library:

import requests
 
proxies = {
    "http": "http://username:password@gateway.example.com:8080",
    "https": "http://username:password@gateway.example.com:8080",
}
 
response = requests.get("https://example.com", proxies=proxies, timeout=30)

For rotating sessions, generate a new session ID per request or per task:

import uuid
 
def get_proxy(country="us"):
    session_id = uuid.uuid4().hex[:8]
    user = f"user-country-{country}-session-{session_id}"
    return {
        "http": f"http://{user}:password@gateway.example.com:8080",
        "https": f"http://{user}:password@gateway.example.com:8080",
    }

Integration in Playwright

Playwright supports proxy configuration at both the browser and context level.

from playwright.sync_api import sync_playwright
 
with sync_playwright() as p:
    browser = p.chromium.launch(
        proxy={
            "server": "http://gateway.example.com:8080",
            "username": "user-country-us",
            "password": "password",
        }
    )
    page = browser.new_page()
    page.goto("https://example.com")
    browser.close()

For per-context proxy rotation, create a new browser context for each session with different proxy parameters — this allows multiple concurrent sessions with different IPs to run within the same browser process.

Integration in Puppeteer

const puppeteer = require("puppeteer");
 
const browser = await puppeteer.launch({
  args: ["--proxy-server=http://gateway.example.com:8080"],
});
 
const page = await browser.newPage();
await page.authenticate({ username: "user-country-us", password: "password" });
await page.goto("https://example.com");

Integration in Selenium

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
 
options = Options()
options.add_argument("--proxy-server=http://gateway.example.com:8080")
 
driver = webdriver.Chrome(options=options)
driver.get("https://example.com")

For authenticated proxies in Selenium, a browser extension or a proxy that supports IP allowlisting simplifies credential passing, since Selenium does not natively support username/password for proxy authentication in the same way Playwright does.

Session Management Patterns

Per-request rotation

For stateless jobs where each URL is independent, generate a new session ID (or omit the session parameter entirely if the gateway rotates automatically) for each request. This distributes requests across the maximum number of unique IPs.

Per-task sticky sessions

For multi-step workflows — a login sequence, a checkout flow, a multi-page search — generate one session ID per task and reuse it for all requests within that task. This ensures the IP remains consistent throughout the workflow.

def run_task(task_id, steps):
    proxy = get_proxy_with_session(session_id=task_id)
    for step in steps:
        response = requests.get(step.url, proxies=proxy, timeout=30)
        # process step

Error Handling for Proxy Integration

Build retry logic that handles both network-level failures (connection timeout, refused connection) and application-level failures (CAPTCHA pages, block responses). On network failures, retry with the same session if the workflow is stateful. On application-level blocks, rotate to a new session.

Use exponential backoff with a cap between retries to avoid hammering a target that has started rate limiting your traffic.

FlameProxies provides gateway endpoints compatible with all the tools above, with standard HTTP/HTTPS proxy support and username-parameter targeting for country, city, and session configuration. The same gateway endpoint handles both rotating and sticky session modes, simplifying the integration across different workflow types.