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
- Use sticky sessions for logins, registration, forms and carts.
- For public-page collection, rotate between task batches.
- Do not change countries on each request for the same account.
- When checks appear, reduce request frequency and review the browser environment before changing exits.
5. Reliability tips
- Set a reasonable timeout, such as 15–30 seconds.
- Limit retries to 2–3 attempts rather than looping indefinitely.
- Record error causes and distinguish proxy failures from destination rejections.
- Group concurrent tasks by country and account; keep sessions separate.
Need residential proxies for scripts?
MooProxy supports HTTP / SOCKS5 for requests, Playwright and Selenium.
Get trial traffic