[Python] How can Playwright send the Proxy-Authorization while using Chromium?

Discussão em 'Python' iniciado por Stack, Setembro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have a proxy server that requires a username and password to access (e.g., 127.0.0.1:8000, username: abcdef, password: 123456).

    When I use Playwright to access a destination website through this proxy, the proxy server receives a blank Proxy-Authorization header, and the website cannot be accessed because the proxy authentication fails. According to the Playwright documentation said it support proxy authentication, proxy authentication should be supported.

    Interestingly, when I test with WebKit, proxy authentication works as expected, but it does not work with Chromium.

    Has anyone encountered this issue or knows how to resolve it? Is there a workaround to get proxy authentication working with Playwright and Chromium?

    Thank you for your help!

    my test code is:

    from playwright.sync_api import sync_playwright
    import subprocess
    import os

    # My Proxy
    server = "http://127.0.0.1:8000"
    password = "abcdef"
    username = "123456"

    dst_url="http://httpbin.org/ip"

    def test_webkit_proxy():
    print("=== Solution1: use WebKit ===")
    with sync_playwright() as p:
    browser = p.webkit.launch()
    context = browser.new_context(
    proxy={
    "server": server,
    "username": username,
    "password": password
    }
    )
    page = context.new_page()
    try:
    response = page.goto(dst_url, timeout=30000)
    if response.status == 200:
    print(f"✅ WebKit success: {response.status}")
    else:
    print(f"❌ WebKit fail: {response.status}")
    print(f"response body: {response.text()}")
    except Exception as e:
    print(f"❌ WebKit fail: {e}")
    finally:
    browser.close()

    def test_chromium_standard():
    print("=== Solution2: use Chromium standard ===")
    with sync_playwright() as p:
    browser = p.chromium.launch()
    context = browser.new_context(
    proxy={
    "server": server,
    "username": username,
    "password": password
    }
    )
    page = context.new_page()
    try:
    response = page.goto(dst_url, timeout=30000)
    if response.status == 200:
    print(f"✅ Chromium standard success: {response.status}")
    else:
    print(f"❌ Chromium standard fail: {response.status}")
    print(f"response body: {response.text()}")
    except Exception as e:
    print(f"❌ Chromium standard fail: {e}")
    finally:
    browser.close()

    if __name__ == "__main__":
    test_webkit_proxy()
    test_chromium_standard()


    I want to use the Playwright Python library with Chromium in a way that supports proxy authentication.

    Continue reading...

Compartilhe esta Página