Python + selenium + firefox proxy does not work

Solution 1:

I also encountered the same problem, the two methods I have tried, indeed are all invalid. But then a feasible way was found.

firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True

PROXY = "58.216.202.149:8118"

firefox_capabilities['proxy'] = {
    "proxyType": "MANUAL",
    "httpProxy": PROXY,
    "ftpProxy": PROXY,
    "sslProxy": PROXY
}

driver = webdriver.Firefox(capabilities=firefox_capabilities)
driver.get(url)

It's run success for me.
It is important to note that:don't to set noProxy with None or '', delete it.
Look at a more detailed description of my blog: http://www.itfanr.cc/

Solution 2:

Just wanted to add that I got my setup working using the below configuration,

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary


profile = webdriver.FirefoxProfile()

user_agent = "Some UserAgent String here..."
proxy_ip = "123.123.123.123"
proxy_port = "12345"

profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", str(proxy_ip))
profile.set_preference("network.proxy.http_port", int(proxy_port))
profile.set_preference("network.proxy.ssl", str(proxy_ip))
profile.set_preference("network.proxy.ssl_port", int(proxy_port))
profile.set_preference("network.proxy.ftp", str(proxy_ip))
profile.set_preference("network.proxy.ftp_port", int(proxy_port))
profile.set_preference("network.proxy.socks", str(proxy_ip))
profile.set_preference("network.proxy.socks_port", int(proxy_port))
profile.set_preference("network.http.use-cache", False)

profile.set_preference("general.useragent.override", user_agent)

profile.update_preferences()
binary = FirefoxBinary("/usr/bin/firefox")
driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary)

driver.get("https://ifconfig.me")

driver.save_screenshot("check_ip.png")
driver.quit()

So simply setting the HTTP proxy to all other protocols got it working. Hope this helps someone.