Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Dynamic Proxy Changing is not working (?) with Flag "--ignore-certificate-errors" #735

Open
Mirrien-Liang opened this issue Dec 20, 2023 · 0 comments

Comments

@Mirrien-Liang
Copy link

Problem behavior:
The dynamic switching of upstream proxy is properly functioning without the flag '--ignore-certificate-error' for a driver instantiation. I simply use driver.proxy = {'http': 'new_proxy'}, and the next driver.get() will be using the new proxy IP. However, without this flag, the accesses to webpages will be blocked by the invalid certificate error raised by Chrome. We tried some other methods but they failed to bypass this warning, (e.g., --ignore-ssl-errors=yes, --allow-insecure-localhost, --allow-running-insecure-content, etc.).

If we add the flag --ignore-certificate-error to Chrome, the warning is gone and webpage access is normal. But in this case, the proxy switching will not work if we change the value of driver.proxy to {'http': 'new_proxy'} or to an empty dict {}. Even though their values were indeed changed, they did not become effective in subsequent navigations.

Any advice would be much appreciated!

A sample of my code:

import seleniumwire.undetected_chromedriver as uc
from selenium.webdriver import Chrome, DesiredCapabilities
from selenium.webdriver.chrome.options import Options
from common import PROXY_USERNAME, PROXY_PASSWORD, PROXY_HOST, PROXY_PORT

# Get proxy for session 12345
seleniumwire_options = {
        "proxy": {
            "http": f"http://{PROXY_USERNAME}-session-{12345}:{PROXY_PASSWORD}@{PROXY_HOST}:{PROXY_PORT}",
            "https": f"http://{PROXY_USERNAME}-session-{12345}:{PROXY_PASSWORD}@{PROXY_HOST}:{PROXY_PORT}",
            "verify_ssl": False,
        },
    }

# Add flag and config
chrome_options = uc.ChromeOptions()
chrome_options.add_argument('--ignore-certificate-errors')

capabilities = DesiredCapabilities.CHROME.copy()
capabilities["acceptInsecureCerts"] = True

# Instantiate a driver
driver = uc.Chrome(
        options=chrome_options,
        desired_capabilities=capabilities,
        seleniumwire_options=seleniumwire_options,
    )

# Check current proxy session
print(driver.proxy)

# Check current IP address
driver.get("http://lumtest.com/myip.json")
print(driver.page_source)

# Swap to a new proxy session 54321 (given a new IP)
driver.proxy = {"http": f"http://{PROXY_USERNAME}-session-{54321}:{PROXY_PASSWORD}@{PROXY_HOST}:{PROXY_PORT}"}

# Check the new proxy IP
print(driver.proxy)
driver.get("http://lumtest.com/myip.json")
print(driver.page_source)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant