selenium: [πŸ› Bug]: Python Proxy configuration with Proxy network

What happened?

proxy I am using a proxy network and want to configure it with Selenium on Python. I have seen many resources use the HOST:PORT method of configuration, but proxy networks uses the β€œURL method” of http://USER:PASSWORD@PROXY:PORT.

See different types of configurations below:

How can we reproduce the issue?

###Selenium_Options###
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://USER:PASSWORD@PROXY:PORT")
driver = webdriver.Chrome(options=options)
driver.get("https://some_url.com")



###Desired_Capabilities###
from selenium import webdriver
from selenium.webdriver.common.proxy import *

proxy_url = "http://USER:PASSWORD@PROXY:PORT"
proxy = Proxy({
    'proxyType': ProxyType.MANUAL,
    'httpProxy': proxy_url,
    'sslProxy': proxy_url,
    'noProxy': ''})

capabilities = webdriver.DesiredCapabilities.CHROME
proxy.add_to_capabilities(capabilities)

driver = webdriver.Chrome(desired_capabilities=capabilities)
driver.get("https://some_url.com")

Relevant log output

Log does not throw any errors with the above configurations, all the errors on on a browser side:

Reference above attached image for Selenium_Options error.

Desired Capabilities does not throw any browser errors, but the configuration still fails to add proxy.

*Proxy β€œURL” is in a working state and has been tested using the requests library.

FOR MORE INFORMATION: https://stackoverflow.com/questions/70806778/python-selenium-proxy-network

Operating System

Windows 10

Selenium version

Tried with: 3.141.0 and 4.0.0a7

What are the browser(s) and version(s) where you see this issue?

Version 101.0.4951.41

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 101.0.4951.41

Are you using Selenium Grid?

NA

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21 (6 by maintainers)

Most upvoted comments

@symonk For extra context, I ran the below code using urllib.request with the proxy endpoint configuration, and the IP is correctly applied and cycled:

import urllib.request
opener = urllib.request.build_opener(
    urllib.request.ProxyHandler(
        {'http': 'http://USER:PASSWORD@PROXY:PORT/',
        'https': 'http://USER:PASSWORD@PROXY:PORT/'}))
print(opener.open('http://lumtest.com/myip.json').read())

The website http://lumtest.com/myip.json can also be used to check one’s personal IP. At this point, is it safe to rule out the validity of the proxy network endpoint, and that this problem solely lies with Selenium?

Opened an issue with the chromedriver project: https://bugs.chromium.org/p/chromedriver/issues/detail?id=4118 Will update this thread when I reach a solution.