Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set SOCKS5 proxy with auth for Chrome in selenium Python?

I'm trying to use SOCKS5 proxy provided by PIA (https://www.privateinternetaccess.com). I generated user/pass for SOCKS5 on their site, but I can't use this information, since I don't know where to put it. I tried using ChromeOptions, but it's not working.

def create_browser(self, proxy):
    """
    proxy = "xGeneratedUser:[email protected]:1080"
    """
    chrome_options = webdriver.ChromeOptions()
    if proxy:
        chrome_options.add_argument("--proxy-server=socks5://" + proxy)
    try:
        self.browser = webdriver.Chrome('./chromedriver', chrome_options=chrome_options)
        self.browser.set_window_size(800, 600)
    except Exception as error:
        return False
like image 530
Fejs Avatar asked Apr 09 '17 22:04

Fejs


2 Answers

In case anyone stumbles on this...

I was trying to connect with a socks5 proxy with selenium and believe the issue was that the proxy requires user/pass auth, and since I was using the chromedriver it did not work because chrome does not natively support this.

Try connecting with a socks5 proxy that does not require auth or finding a driver that supports this - not aware of which/what this might be though.

like image 145
Kevin Avatar answered Nov 15 '22 04:11

Kevin


I am stumping in here too. I also want to use auth proxy in the chrome webdriver of selenium. I have tried use httpProxy or PAC, in which we cannot use username and password.

And then I saw the socksUsername and socksPassword but it is still useless. Because the error:

selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: cannot parse capability: proxy
from invalid argument: Specifying 'socksProxy' requires an integer for 'socksVersion'
  (Driver info: chromedriver=73.0.3683.20 (8e2b610813e167eee3619ac4ce6e42e3ec622017),platform=Mac OS X 10.14.3 x86_64)

I found chrome code said need the socksProxy key, but the current selenium is not support socksProxy, see selenium code.

So I have to choose other way:

  • set http_proxy in PATH, with export http_proxy=http://username@pass:host:port
  • use extension to hack

UPDATE: Finally, I use pproxy make as a proxy redirector on local.

# pproxy -r ${HTTP_PROXY}\#${PROXY_AUTH} -l http://:8080 -v
# 1.2.3.4:1234 is remote address:port, username and password is used auth for remote proxy.

 pproxy -r http://1.2.3.4:1234\#username:password  -l http://:8080 -v

So now your can connect to your localhost:8080 without auth.

like image 44
michael Avatar answered Nov 15 '22 05:11

michael