2

I want to use proxy with username and password in my docker selenium container.

I tried every solution that I found on so and it doesn't work. I tried http proxy:

capabilities = DesiredCapabilities.FIREFOX
        capabilities['proxy'] = {
            'proxyType': 'MANUAL',
            'httpProxy': f'{proxy.ip_address}:{proxy.port}',
            'sslProxy': 'ip:port',
            'socksUsername': proxy.login,
            'socksPassword': proxy.password
        }
browser = webdriver.Remote(command_executor='http://hub:4444/wd/hub',
                               desired_capabilities=capabilities,
                               browser_profile=profile)

selenium.common.exceptions.InvalidArgumentException: Message: Invalid proxy configuration entry: socksPassword

tried socks proxy:

proxy = Proxy({
                    'proxyType': ProxyType.MANUAL,
                    'socksProxy': f'{proxy.ip_address}:{proxy.port}',
                    'socksUsername': proxy.login,
                    'socksPassword': proxy.password
                })

browser = webdriver.Remote(command_executor='http://hub:4444/wd/hub',
                                   desired_capabilities=capabilities,
                                   browser_profile=profile,
                                   proxy=proxy)

Message: Invalid proxy configuration entry: socksPassword

I also tried to set proxy via firefox profile, like here, but it seems not working because there is no option to set password for proxy.

Proxy is working because when i do request:

proxy = 'socks5://username:password@ip:port' resp = requests.get('https://api.ipify.org?format=json',
                                    proxies=dict(http=proxy,
                                                 https=proxy)) print(resp.json())

returns correct result

Arti
  • 7,356
  • 12
  • 57
  • 122

2 Answers2

0

The only solution is using proxy without password

Arti
  • 7,356
  • 12
  • 57
  • 122
0

Python3. You need to pip3 install geckodriver

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions

firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True

# https://free-proxy-list.net/
proxy = '78.96.125.24:3128'    

firefox_capabilities['proxy'] = {
    "proxyType": "MANUAL",
    "httpProxy": proxy,
    "ftpProxy": proxy,
    "sslProxy": proxy,
}

browser = webdriver.Firefox(capabilities=firefox_capabilities)
browser.get('https://httpbin.org/ip')
# browser.get('https://www.google.pl')
Jakub Ujvvary
  • 421
  • 4
  • 13