Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1580

Selenium Java set SOCKS5 proxy

$
0
0

I'm trying to set a SOCKS5 proxy when the driver starts so that all requests go through this proxy. I'm trying to set a proxy this way, but I get the error.

Proxy proxy = new Proxy();proxy.setProxyType(Proxy.ProxyType.MANUAL);String proxyHost = "host";int proxyPort = port;String proxyUsername = "username";String proxyPassword = "password";proxy.setSocksProxy(proxyHost +":" + proxyPort);proxy.setSocksVersion(5);proxy.setSocksUsername(proxyUsername);

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 400. Message: Invalid proxy configuration entry: socksUsernameHost info: host: 'OWNER', ip: ''Build info: version: '4.10.0', revision: 'c14d967899'System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.8'Driver info: org.openqa.selenium.firefox.FirefoxDriverCommand: [null, newSession {capabilities=[Capabilities {acceptInsecureCerts: true, browserName: firefox, moz:debuggerAddress: true, moz:firefoxOptions: {}, proxy: Proxy(manual, socks=107.164...}]}]

All my proxy information is completely correct and it works. If I specify .setSocksPassword() in the proxy, I get the same error, only with the message Invalid proxy configuration entry: socksPassword

I tried to connect a proxy through the BrowserMobProxy library this way:

String proxyHost = "host";        int proxyPort = port;        String proxyUsername = "username";        String proxyPassword = "password";        BrowserMobProxy proxy = new BrowserMobProxyServer();        proxy.start(0);        Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);        seleniumProxy.setProxyType(Proxy.ProxyType.MANUAL);        seleniumProxy.setSocksVersion(5);        seleniumProxy.setSocksPassword(proxyPassword);        seleniumProxy.setSocksUsername(proxyUsername);        seleniumProxy.setSocksProxy(proxyHost +":" + proxyPort);        WebDriverManager.chromedriver().setup();        ChromeOptions options = new ChromeOptions();        options.setCapability("proxy", seleniumProxy);        options.setProxy(seleniumProxy);        options.addArguments("--headless");        WebDriver driver = new ChromeDriver(options);        proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);        driver.get("http://ident.me/");        String ipAddress = driver.findElement(By.tagName("body")).getText();        System.out.println("ip: " + ipAddress);        proxy.newHar("proxy_test");        driver.quit();

In this case, I no longer receive an error, but now a problem arises due to the fact that the proxy is simply not visible to the driver, as I understand it. Through the ident me service I receive my own IP, and not the proxy address that I expected to receive. How can I fix this situation?

I also tried connecting not to a SOCKS5 proxy, but to an HTTPS proxy. The result I got was the same as in the last case with BrowserMobProxy, that is, the proxy was simply not used and I received my IP address at the output, not the proxy address.


Viewing all articles
Browse latest Browse all 1580

Trending Articles