I am trying to write an automation script that uses a proxy. I initially tried using Selenium, but it doesn't offer an easy way to authenticate the proxy since Selenium can't interact with the authentication popup. I then switched to Playwright, where it appears that proxy authentication is supported as per the documentation here.
Below is my code snippet:
# Relevant code for initializing proxy and launching browser
proxy = {
"server": f"http://{proxy_info['host']}:{proxy_info['port']}",
"username": proxy_info['username'],
"password": proxy_info['password']
}
# Initialize Playwright and launch browser
with sync_playwright() as p:
browser = p.chromium.launch(proxy=proxy)
page = browser.new_page()
page.goto("https://www.google.com", timeout=60000)
# Rest of the code
When I run the script, I get the following error:
playwright._impl._api_types.Error: net::ERR_TUNNEL_CONNECTION_FAILED at https://www.google.com/
The script works fine when I run it without the proxy settings. I am new to both proxies and Playwright, so I'm not sure what the issue is or how to fix it. Are there any better ways to handle browser automation with proxies?