SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.5k stars 8.15k forks source link

Proxy Authentication Does Not Work #7911

Closed nomaam closed 2 years ago

nomaam commented 4 years ago

🐛 Bug Report

Unable to use proxy with username / password

To Reproduce

Documentation

https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#proxy-json-object

Error thrown

Message: Invalid proxy configuration entry: socksPassword

Expected behavior

To retrieve the website without errors

Test script or set of commands reproducing this issue

Code - Python

fireFoxOptions = webdriver.FirefoxOptions()
fireFoxOptions.set_headless()

PROXY = "myproxy.com:8080"

webdriver.DesiredCapabilities.FIREFOX['proxy']={
    "httpProxy":PROXY,
    "ftpProxy":PROXY,
    "sslProxy":PROXY,
    "socksProxy":PROXY,
    "socksUsername":"proxyusername",
    "socksPassword":"proxypassword",
    "noProxy":[],
    "proxyType":"MANUAL"
}

browser = webdriver.Firefox(firefox_options=fireFoxOptions)
browser.get('https://www.google.com/')

Error thrown

Message: Invalid proxy configuration entry: socksPassword

Environment

OS: Debian Browser: Latest version of Firefox and Chrome Browser version: Latest as of 2020-01-03 Browser Driver version: Latest as of 2020-01-03 Language Bindings version: Python Latest as of 2020-01-03

donky106 commented 4 years ago

Hi, I would like to work on this issue

mmphego commented 4 years ago

Has anyone made any progress with this issue? I'm also experiencing the same issue.

selenium.__version__                                                                                                                                                             
Out[24]: '3.141.0'
mpizosdim commented 3 years ago

any solution here how to pass authentication credentials?

mmphego commented 3 years ago

@mpizosdim take a look at https://github.com/wkeeling/selenium-wire, it worked for me. Good luck

marepop commented 3 years ago

Not everyone can use selenium-wire. Is there any solution or a workaround to this?

GQAssurance commented 2 years ago

This almost certainly is not a Selenium bug.

socksUsername & socksPassword were removed from the WebDriver spec long ago. This is the mozilla bug report

Your code should authenticate within the webdriver spec, e.g.

PROXY = "proxyusername:proxypassword@myproxy.com:8080"

webdriver.DesiredCapabilities.FIREFOX['proxy']={
    "httpProxy":PROXY,
    "sslProxy":PROXY,
    "socksProxy":PROXY,
    "noProxy":[],
    "proxyType":"MANUAL"
}

Probably the reason that Selenium-Wire works is because it follows the current webdriver spec.

FYI, ftpProxy was also removed from Firefox as of version 90......

titusfortner commented 2 years ago

For Selenium 4, first make sure it is a valid w3c session by using firefox options class

from selenium.webdriver.firefox.options import Options as FirefoxOptions

options = FirefoxOptions()

The proxy object gets set a property on that class: https://github.com/SeleniumHQ/selenium/blob/41a34dfbdfc70c90cc133e9a9cf5470236f0ff5e/py/selenium/webdriver/common/options.py#L204

options.proxy = proxy

The proxy itself is defined here: https://w3c.github.io/webdriver/#proxy and specifies:

A host and optional port for a scheme is defined as being a valid host, optionally followed by a colon and a valid port. The host may include credentials.

So you *should be able to do:

proxy = Proxy()
proxy.socks_proxy = "username:password@myproxy.com:8080"

Except that Firefox does not yet support this: https://github.com/mozilla/geckodriver/issues/1872

Not much work has been done on it either: https://bugzilla.mozilla.org/show_bug.cgi?id=1395886

There's nothing more Selenium can do for this. I've seen suggestions for using an intermediary proxy to manage credentials.

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.