A
A
agent_22032020-10-13 13:18:42
Python
agent_2203, 2020-10-13 13:18:42

How to install socks5 proxy with authorization in Firefox in selenium?

When I use proxy without username and password everything works fine

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.proxy import *

profile = webdriver.FirefoxProfile() 

profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.socks", "ip")
profile.set_preference("network.proxy.socks_port", port)
profile.set_preference("network.proxy.socks_version", 5)
profile.update_preferences()

driver = webdriver.Firefox(firefox_profile=profile)

driver.get("http://api64.ipify.org")
print(driver.page_source)

driver.close()
driver.quit()


However, when I try to login with username and password

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.proxy import *

profile = webdriver.FirefoxProfile() 

profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.socks", "ip")
profile.set_preference("network.proxy.socks_port", port)
profile.set_preference("network.proxy.socksUsername", "username")
profile.set_preference("network.proxy.socksPassword", "password")
profile.set_preference("network.proxy.socks_version", 5)
profile.update_preferences()

driver = webdriver.Firefox(firefox_profile=profile)

driver.get("http://api64.ipify.org")
print(driver.page_source)

driver.close()
driver.quit()


An error occurs
Traceback (most recent call last):
  File "step_one.py", line 22, in <module>
    driver.get("http://api64.ipify.org")
  File "/usr/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "/usr/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=connectionFailure&u=http%3A//api64.ipify.org/&c=UTF-8&d=Firefox%20can%E2%80%99t%20establish%20a%20connection%20to%20the%20server%20at%20api64.ipify.org.


I also changed network.proxy.socksUsername to network.proxy.socks_username, - password is the same. But the error is the same

Who knows how to solve? Or is there another way to login?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
agent_2203, 2020-10-14
@agent_2203

How to manage firefox extension in selenium?

A
Alexey Dmitriev, 2020-10-13
@SignFinder

Firefox should not care where the socks proxy server will authorize users.
Try FoxyProxy extension to connect to socks5 proxy with login and password.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question