How to use an authenticated proxy with Selenium and Chrome
Selenium sets a proxy through browser options, but Chrome has no way to take an HTTP proxy's username and password from them, and it ignores credentials placed in the proxy address. This guide sets up the proxy in Python with Chrome, explains the gap and walks through the workarounds developers use to fill it.
HOST, PORT, USERNAME and PASSWORD stand for the values from your dashboard. Plans are on pricing.
AtlasProxies Team · Updated · 5 min read
- 1Options Set the Address OnlySelenium's Proxy object and Chrome's --proxy-server both route traffic, but neither carries the HTTP login.
- 2Answer the Login Another WayA BiDi auth handler, a small extension or a local forwarder supplies the username and password.
- 3Expect Retries Around RotationSelenium sessions outlast one IP, so retry page loads that fail when the timer fires.
On This Page
Set the proxy address in Python
Selenium's documented way is a Proxy object on the options:
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
options = webdriver.ChromeOptions()
options.proxy = Proxy({'proxyType': ProxyType.MANUAL, 'httpProxy': 'HOST:PORT', 'sslProxy': 'HOST:PORT'})
driver = webdriver.Chrome(options=options)Set sslProxy as well as httpProxy, or HTTPS sites will not use the proxy.
Chrome also has its own switch, which does the same job in one line:
options.add_argument('--proxy-server=http://HOST:PORT')Either form only tells Chrome where the proxy is. With the proxy set to HTTP and no login supplied, Chrome stops at the proxy's authentication request. A visible browser shows a sign-in dialog that WebDriver cannot fill, and a headless one fails to load the page.
Why the login has nowhere to go
Chrome reads no username or password from --proxy-server. Credentials in that string are dropped, a behavior recorded in Chromium's issue tracker.
Selenium's Proxy object does have socksUsername and socksPassword fields. Chromium's proxy documentation states that Chrome supports no authentication methods for SOCKSv5, so those fields do not help in Chrome. Older guides point to Selenium Wire, which added a login through its own proxy layer. Its repository was archived in January 2024 and no longer receives fixes.
Workaround 1: a BiDi authentication handler
Selenium 4 includes WebDriver BiDi network features, and its documentation shows an authentication handler in Python. Turn BiDi on before starting the driver, then add the handler:
options.enable_bidi = True
driver = webdriver.Chrome(options=options)
handler_id = driver.network.add_auth_handler('USERNAME', 'PASSWORD')The handler answers authentication requests with those credentials, and "driver.network.remove_auth_handler(handler_id)" removes it later.
This option needs the least code and nothing beyond Selenium. The example in Selenium's own documentation runs against Firefox and a site's Basic Auth page, so test it against the proxy in your Chrome version before relying on it, and keep Selenium up to date.
Workaround 2: a small Chrome extension
Chrome extensions can supply proxy credentials through the webRequest API. A Manifest V3 extension with the webRequest and webRequestAuthProvider permissions, plus host permissions for the sites you visit, registers a listener on chrome.webRequest.onAuthRequired with the asyncBlocking option and passes back authCredentials holding USERNAME and PASSWORD. The details the listener receives include isProxy, so the extension can answer only the proxy's request.
Loading it is where Chrome versions matter. From Chrome 137, branded Google Chrome ignores the --load-extension switch. Chromium and Chrome for Testing still accept it, so set options.binary_location to one of those builds and add:
options.add_argument('--load-extension=/path/to/extension')Write USERNAME and PASSWORD into the extension's files at build time from your environment, and keep that folder out of version control.
Workaround 3: a local forwarding proxy
The third approach takes the login out of the browser entirely. A small proxy runs on your own machine, listens on 127.0.0.1 without a password, and forwards every connection to HOST:PORT with USERNAME and PASSWORD added. Chrome is then pointed at the local address with --proxy-server=http://127.0.0.1:LOCAL_PORT and never sees a login request.
Several open-source forwarders do this, and the same setup serves other tools on the machine that cannot send a proxy login. Bind the forwarder to 127.0.0.1 only, so no other device on your network can use your proxy through it.
Check that traffic uses the proxy
Load https://api.ipify.org with driver.get and read driver.find_element(By.TAG_NAME, 'body').text. The address should match Current Public IP in the proxy's IP Rotation panel. If it shows your own IP, sslProxy is probably missing. If the page fails at the proxy, the login did not reach it, and 407 Proxy Authentication Required lists what to check.
Long Selenium sessions and the rotation timer
A Selenium suite or crawl often runs longer than one rotation interval. When the timer you set fires, anywhere from every 5 to every 120 minutes, the proxy moves to a new IP while HOST, PORT and the login stay put. Chrome keeps the session, cookies and open windows. A page load that overlaps the change can end in a network error, which driver.get raises as a WebDriverException.
The IP cannot be changed early from a script or from the dashboard, so the script should expect the change.
- Wrap driver.get in a retry that catches WebDriverException, waits briefly and loads the URL again.
- Repeat only idempotent steps automatically. Reloading a listing page is harmless, while clicking Submit twice may not be.
- Use explicit waits with WebDriverWait after a retry, since the reloaded page can take a moment longer.
- Record the exit IP at checkpoints, so a failed step can be matched to a rotation.
Interval and data use for Selenium runs
A timer longer than one suite run keeps the whole run on one IP. Rotating mobile proxies explains the options, and automation proxies covers scheduled jobs.
On Eco and Pro, unlimited bandwidth comes with 15 GB/day of fair use. A proxy that reaches 15 GB in a day stops until the limit resets the next day, while Ultra is truly unlimited.
Good to Know. Keep automated browsing within each website's terms and our Acceptable Use Policy.
Frequently Asked Questions
Why does Selenium ignore my proxy username and password?
Chrome does not read credentials from the proxy setting Selenium passes to it. Supply them with a BiDi auth handler, an extension or a local forwarder.
Can I use a SOCKS5 proxy with a login in Selenium and Chrome?
Not directly. Chrome supports no SOCKS5 authentication, so switch the proxy to HTTP in My Proxies and use one of the workarounds for the login.
Is Selenium Wire still maintained?
No. Its repository was archived in January 2024. Selenium's own BiDi network features are the maintained route for answering login requests.
Why does --load-extension do nothing in my Chrome?
Branded Google Chrome ignores it from version 137. Load the extension in Chrome for Testing or Chromium instead.
Does a rotation end my Selenium session?
No. The browser session and cookies stay. Retry any page load that failed at the moment the IP changed.