Skip to main content

Authenticated and rotating proxies for Playwright — turn user:pass proxy URLs into Playwright's proxy dict and rotate per context.

Project description

playwright-proxy-authentication

PyPI version Python versions License: MIT

Use authenticated and rotating proxies with Playwright without fighting its proxy API. Turn an ordinary scheme://user:pass@host:port URL into the dict Playwright expects, and hand out a fresh exit IP per browser context.

pip install playwright-proxy-authentication

The problem

Unlike requests or Scrapy, Playwright ignores credentials in a proxy URL. This silently fails to authenticate:

# ❌ username/password are dropped — you get 407 Proxy Authentication Required
browser.new_context(proxy={"server": "http://user:pass@gw.example.com:913"})

Playwright wants the parts split out:

# ✅ correct
browser.new_context(proxy={
    "server": "http://gw.example.com:913",
    "username": "user",
    "password": "pass",
})

This package does that conversion for you, and adds per-context rotation.

Usage

from playwright.sync_api import sync_playwright
from playwright_proxy_auth import ProxyPool

# A rotating residential gateway gives a new exit IP on every connection.
pool = ProxyPool(gateway="http://USERNAME:PASSWORD@us.jibaoproxy.com:913")

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    for _ in range(3):
        context = browser.new_context(proxy=pool.get())   # fresh IP per context
        page = context.new_page()
        page.goto("https://httpbin.org/ip")
        print(page.inner_text("body"))
        context.close()
    browser.close()

Static list instead of a gateway:

pool = ProxyPool(proxies=[
    "http://USERNAME:PASSWORD@proxy-a.example.com:8000",
    "http://USERNAME:PASSWORD@proxy-b.example.com:8000",
])

One-off conversion without the pool:

from playwright_proxy_auth import to_playwright_proxy
proxy = to_playwright_proxy("http://user:pass@gw.example.com:913")
browser.new_context(proxy=proxy)

See examples/ for the async version.

Gotchas this saves you from

  • Credentials in the URL are ignored — they must be a separate username/password. (Main reason for it.)
  • Authenticated SOCKS5 is not supported by Playwright. A socks5://user:pass@… URL raises a clear error instead of failing silently — use an HTTP/HTTPS gateway for authenticated rotation.
  • Proxy is per context, not per page. Rotate by creating a new browser.new_context(proxy=...); pages inside a context share its exit IP.

A note on getting blocked anyway

A correctly authenticated proxy still gets blocked if the exit IP is a datacenter range — anti-bot systems score the ASN and TLS/JA3 fingerprint before your page loads. Residential exits with clean ASN reputation are what pass. We build JiBao Proxy for this: 72M+ residential IPs across 200+ countries with sticky sessions. This package works with any HTTP proxy provider, though.

Related

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

playwright_proxy_authentication-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file playwright_proxy_authentication-0.1.0.tar.gz.

File metadata

File hashes

Hashes for playwright_proxy_authentication-0.1.0.tar.gz
Algorithm Hash digest
SHA256 641e7a7f7c82c1096b7ce7da17c48ca240636546ceee57339c7e5c2bd22a2fb9
MD5 fe47fc698604449ed2dc18f61782038d
BLAKE2b-256 adbad6d6d3d16e0ae6e95201db9e55e2bc08e5e4b1ccf97b5f869727a7d539c0

See more details on using hashes here.

File details

Details for the file playwright_proxy_authentication-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for playwright_proxy_authentication-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 056c0ee108c867db7aa18b2c7791f0ea0944affff32cfb14f645acd9b2525893
MD5 725142de3c288870a390e336fa08a298
BLAKE2b-256 74973d44200ea99a191e0671f1828c4f2836adb6b699d69411c8e76193b15ecc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page