Skip to content

How to use proxies with Python requests and Playwright

Focus on proxy format, credentials, timeouts and retries. Avoid endless retries on one exit or switching IPs on every request within a logged-in workflow.

1. Proxy formats

Common HTTP proxy format:

http://username:password@host:port

Common SOCKS5 proxy format:

socks5://username:password@host:port

Preserve all country, city and session parameters in the generated credentials.

2. HTTP proxies with requests

import requests

proxy = "http://username:[email protected]:55688"
proxies = {
    "http": proxy,
    "https": proxy,
}

resp = requests.get("https://example.com", proxies=proxies, timeout=20)
print(resp.status_code)

Set a timeout and handle connection failures, timeouts and destination responses such as 429 or 403.

3. Proxies with Playwright

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(
        proxy={
            "server": "http://us.mooproxy.net:55688",
            "username": "your_username",
            "password": "your_password",
        }
    )
    page = browser.new_page()
    page.goto("https://example.com")
    print(page.title())
    browser.close()

4. When to keep a session

5. Reliability tips

Need residential proxies for scripts?

MooProxy supports HTTP / SOCKS5 for requests, Playwright and Selenium.

Get trial traffic