Proxy setup in Selenium (Python)

Selenium with Prokso proxies in Python: --proxy-server for Chrome, the IP whitelist instead of a username and password, selenium-wire, one port per browser.

Updated · Prokso editorial team

Markdown, ready to paste into ChatGPT or another AI assistant
Connection details
Host
gw.prokso.com
Port
823 HTTP · 824 SOCKS5 - new IP per request · 10000–20000 sticky session, HTTP(S) and SOCKS5
Username and password
in your dashboard, on the plan page

Your dashboard generates ready-made lines in the format you need: choose the country, IP type and protocol.

Key takeaways
  • Chrome under Selenium takes only the host and port; a username in the proxy address is not used
  • Instead of a password - the IP whitelist, up to 5 addresses per plan
  • The correct result - the proxy IP in the text of the api.ipify.org page that the script printed
Proxies in Selenium: a short video guide · 0:35 · Open the video page
Video transcript

Prokso proxies in Selenium.

First, get your proxy details from the dashboard: host, port, username and password. They are on the plan page, in the Access block.

In Selenium, pass the proxy address in the Chrome launch options. A password cannot be passed this way, so add your IP address to the IP whitelist in the dashboard.

Run the example: the output should show the proxy IP, not yours. On a sticky port the address stays the same.

The full guide with examples is on the Prokso website.

A step-by-step guide to connecting Prokso proxies in Selenium (Python). It takes a few minutes.

Step 1. Chrome under Selenium needs only the host and port

Selenium passes the proxy to Chrome as an address with a host and port: through the --proxy-server argument or through the Proxy object in the browser options, as shown in the Selenium documentation. A username and password in this address will not help: the Chromium documentation says that Chrome does not use credentials written into the proxy settings.

So from the plan page you need only the host gw.prokso.com and the port, and the IP whitelist replaces the password, as described in the next step. If you prefer a ready-made line, the generator's advanced mode has the host:port (IP whitelist) format: it is exactly what goes after --proxy-server=http://.

For a script that goes through several pages of one site, choose "Sticky session" in the "IP address" field: a port from the 10000-20000 range keeps one address for 1 to 120 minutes. Port 823 changes the IP for every request, and separate pages will open from different addresses. The country is set in the plan's pool settings, not in the username, since there is no username here.

The “Access” block on the plan page: host, ports, username and password for the proxy line
The “Access” block on the plan page: host, ports, username and password for the proxy line

Step 2. Add your IP to the IP whitelist

Chrome doesn't accept a username and password in --proxy-server, so the simplest way is to open your plan page in the dashboard and, in the IP whitelist (no password) block, add the IP of the computer or server that runs the script (up to 5 addresses). The proxy then lets you in without a password.

Step 3. Pass the proxy to Chrome

Run pip install selenium and set the proxy with --proxy-server: host gw.prokso.com and a port. To keep one IP for the whole browser session, use a sticky port from 10000-20000 so pages don't load from different IPs.

# pip install selenium   (the computer's IP is added to the IP whitelist)
from selenium import webdriver
from selenium.webdriver.common.by import By

opts = webdriver.ChromeOptions()
opts.add_argument("--proxy-server=http://gw.prokso.com:10001")
driver = webdriver.Chrome(options=opts)
driver.get("https://api.ipify.org")
print(driver.find_element(By.TAG_NAME, "body").text)
driver.quit()

Step 4. If you need username and password authentication

If the IP whitelist doesn't fit (say, your server IP changes often), you can route traffic through selenium-wire, which adds the username and password for you. Note that this project is no longer maintained, so it may break on newer Selenium versions.

# pip install selenium-wire   (no longer maintained)
from seleniumwire import webdriver

sw = {"proxy": {"http": "http://USERNAME:PASSWORD@gw.prokso.com:823",
                "https": "http://USERNAME:PASSWORD@gw.prokso.com:823"}}
driver = webdriver.Chrome(seleniumwire_options=sw)
driver.get("https://api.ipify.org")
print(driver.page_source)
driver.quit()

Step 5. Print the text of the ipify page opened from Selenium

Run the example: Chrome controlled by Selenium opens https://api.ipify.org, and the script prints the page text. It should be the proxy IP, not the address of the computer the script runs on. On a sticky port a second run gives the same address until the session duration runs out.

If a window asking for a username appears instead of an IP, the proxy did not recognize the script's address: it is not in the IP whitelist or it has changed. Check the server's current address and compare it with the list on the plan page.

A regular browser on your computer works without the proxy, so the My IP page in it will show your address. Look only at what the script printed.

Example run: the output shows the proxy IP, not yours. On a sticky port the address stays the same
Example run: the output shows the proxy IP, not yours. On a sticky port the address stays the same

If the server's address changes

Access by IP is convenient as long as your computer or server has a permanent external address. With home internet and some cloud servers the address changes, and the proxy stops letting the script in. The telltale sign: everything worked yesterday, and today Chrome shows a login prompt. Check the current address with the curl https://prokso.com/ip command without a proxy and update it on the plan page.

How to cut traffic use

Turn off image loading in the Chrome settings and run the browser without a window: images are not needed for data collection.

opts = webdriver.ChromeOptions()
opts.add_argument("--proxy-server=http://gw.prokso.com:10001")
opts.add_argument("--headless=new")
# do not load images: saves most of the page weight
opts.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
driver = webdriver.Chrome(options=opts)

Waits and timeouts

Pages open more slowly through a proxy than they do directly. Instead of fixed-length pauses, use explicit waits with WebDriverWait: the script will continue as soon as the element appears. The overall load limit is set by driver.set_page_load_timeout(): set it with some margin, for example 60 seconds.

If the page does not open

  • A login prompt appears. The script's IP has not been added to access by IP, or it has changed.
  • ERR_PROXY_CONNECTION_FAILED. Check the host and port in --proxy-server.
  • ERR_TUNNEL_CONNECTION_FAILED. The proxy refused the connection: most often the plan has run out of traffic.
  • TimeoutException. The page did not finish loading in time: increase the limit or check whether the site itself is responding.

If the proxy does not work

FAQ

Why doesn't http://username:password@host work in --proxy-server?

Chrome ignores credentials in that flag by design. That's why you need the IP whitelist or a tool that answers the authentication request for you.

How do I run several browsers with different IPs?

Give each Chrome instance its own sticky port from 10000-20000. Each port keeps its own IP.

How do I get an IP from the right country through Selenium?

Switch to advanced mode (Settings → Settings mode → Advanced), open your plan and set default countries in Pool settings, then the IP whitelist will give addresses from those countries.

Does --proxy-server work in Chrome headless mode?

Yes. The --proxy-server argument works the same with a window and without one.

Can I use Firefox instead of Chrome?

Yes. In Firefox the proxy is set through the profile settings rather than a launch argument. It does not accept a username and password from code either, so access by IP remains the simplest way.

Was this guide helpful?

Proxy not working? Check it in 6 steps

Install the Prokso app