6

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:GeneratedPass@proxy-nl.privateinternetaccess.com: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
Fejs
  • 2,734
  • 3
  • 21
  • 40
  • Well, not sure I'm helping, but just know [Squid](http://www.squid-cache.org/) is a good and quick way to setup a http to socks5 proxy. You just have to set Chrome proxy to you local http to socks5 proxy. – Arount Apr 19 '17 at 23:41
  • I've answered your question, also a recommendation is to use PhantomJS instead of GoogleChrome driver since it uses a little bit more space/memory/cpu. – innicoder Apr 23 '17 at 15:43

5 Answers5

2

I am stumping 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:

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.

michael
  • 744
  • 7
  • 15
1

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.

Kevin
  • 177
  • 1
  • 15
0

selenium.webdriver.chrome.webdriver

WebDriver(executable_path='chromedriver', port=0, chrome_options=None, service_args=None, desired_capabilities=None, service_log_path=None)

Args :

  • executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
  • port - port you would like the service to run, if left as 0, a free port will be found.
  • desired_capabilities: Dictionary object with non-browser specific capabilities only, such as “proxy” or “loggingPref”.
  • chrome_options: this takes an instance of ChromeOptions

You may follow the table from below URL to write a proxy dictionary object for desired_capabilities. DesiredCapabilities - Proxy JSON Object

Frye Lee
  • 25
  • 5
M. Leung
  • 1,621
  • 1
  • 9
  • 9
  • Already tried both `chrome_options` and `desired_capabilities`, but no luck. – Fejs Apr 18 '17 at 22:07
  • 2
    Well, found that SOCKS Authentication is not implemented in Chrome. Socks_Proxy removed in Proxy manual setting on chrome_options and desired_capabilities even, only http/ftp/ssl available. Maybe try other browser. – M. Leung Apr 19 '17 at 04:55
0

You can try following alternative : -

  • In your .bashrc set proxy that will be used by chrome itself :-

    export http_proxy="xGeneratedUser:GeneratedPass@proxy-nl.privateinternetaccess.com:1080"
    
    export https_proxy="xGeneratedUser:GeneratedPass@proxy-nl.privateinternetaccess.com:1080"
    
  • Otherwise you can use try this tool :- proxy login automator

On windows, for http/https proxy with or without authentication, run one of the following commands in cmd.exe :-

set http_proxy=http://your_proxy:your_port
set http_proxy=http://username:password@your_proxy:your_port
set https_proxy=https://your_proxy:your_port
set https_proxy=https://username:password@your_proxy:your_port
toanant
  • 331
  • 3
  • 9
  • Sorry, forgot to mention: OS in use is Windows, not Linux, so this won't help. – Fejs Apr 21 '17 at 07:55
  • For setting environment variables on windows see [here](https://docs.cloudfoundry.org/cf-cli/http-proxy.html) – toanant Apr 23 '17 at 17:09
  • Doesn't work either. Tried both solutions with user/pass data, but it can't resolve proxy auth. – Fejs Apr 26 '17 at 06:35
0

Yes, try this:

var client = require('webdriverio').remote({ host: 'username:password@127.0.0.1' port: 1234, desiredCapabilities: { browserName: 'chrome' } })