Issue
I am setting up proxy for Firefox driver with Selenium on Python.
I followed this instruction to setup the proxy: https://github.com/luminati-io/api/blob/master/python/3.x/simple.py
username = 'lum-customer-CUSTOMER-zone-YOURZONE'
password = 'YOURPASS'
port = 22225
session_id = random.random()
super_proxy_url = ('http://%s-session-%s:%[email protected]:%d' %
(username, session_id, password, port))
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': super_proxy_url,
'ftpProxy': super_proxy_url,
'sslProxy': super_proxy_url,
'noProxy': '' # set this value as desired
})
print(proxy)
driver = webdriver.Firefox(executable_path = "./bin/geckodriver", proxy=proxy)
driver.get('https://www.google.com')
But it 's seem that the proxy is not work. I am always can connect to the site even if I setup a wrong use/password and host url for the proxy.
Did I missed something?
Any idea is appreciate. Thanks!
Solution
Finally, I found the solution by myself, then I push it here for brothers who need it:
From geckodriver v0.19.1, they remove socketUsername and socketPassword. Therefore we can not use "http://username-sessionid-:[email protected]:port" anymore.
Solution are: save username and password to firefox profile and retrieve it. Or we can enter password and username when firefox ask it as bellow:
class SeleniumWebDriver:
# Set proxy url and proxy port via proxy_url
def get_proxy_cabability(proxy_url):
desired_capability = webdriver.DesiredCapabilities.FIREFOX
desired_capability['proxy'] = {
"proxyType": "manual",
"httpProxy": proxy_url,
"ftpProxy": proxy_url,
"sslProxy": proxy_url,
"socksVersion": 4
}
return desired_capability
#get driver
def get_driver(proxy_url):
desired_capability = self.get_proxy_cabability(proxy_url)
driver = webdriver.Firefox(capabilities=desired_capability, log_path=log_path)
return driver
def set_auth_proxy(username, password):
try:
# Force driver show authentication dialog
self.driver.get('http://www.google.com/')
# Waiting for alert
WebDriverWait(self.driver, 20).until(
ec.alert_is_present())
alert = self.driver.switch_to_alert()
# send auth information
alert.send_keys(username + Keys.TAB + password)
time.sleep(3)
alert.accept()
except Exception as e:
raise Exception("Can not authenticate proxy server")
Answered By - Nhan Phan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.