Python undetected_chromedriver concurrency issues

Viewed 189

We are having problems running multiple concurrent Python Selenium bots on the same server as this code is apparently using the system chromedriver, even though we think it should be using the one in the Python project folder. What option are we missing that enables that functionality correctly?

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from seleniumwire import webdriver as sw_webdriver
import undetected_chromedriver.v2 as uc

dir_path = os.path.dirname(os.path.realpath(__file__))
binary_path = os.path.join(dir_path, "bin", "chromium-browser")
chromedriver_path = os.path.join(dir_path, "bin", "chromedriver")
ser = Service(chromedriver_path)
options = webdriver.ChromeOptions()
options.binary_location = binary_path
options.add_argument('--headless')
options.add_argument("--disable-gpu")
options.add_argument('--no-sandbox')
options.add_argument("--disable-setuid-sandbox")
dbug_port = random.randrange(20000,30000)
options.add_argument(f"--remote-debugging-port={dbug_port}")
options.add_argument("--disable-dev-shm-using")
options.add_argument("--disable-extensions")
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
try:
    logger.info("creating driver")
    sw_options = {  # NOTE: Changed from 'options' to
        "ignore_http_methods": [],  # 'sw_options' so no overwrite
        "proxy": {
            "http": "http://"
                    + proxy_user
                    + ":"
                    + proxy_pass
                    + "@"
                    + proxy_ip
                    + ":"
                    + str(proxy_port),
                    "https": "https://"
                        + proxy_user
                        + ":"
                        + proxy_pass
                        + "@"
                        + proxy_ip
                        + ":"
                        + str(proxy_port),
            "no_proxy": "localhost,127.0.0.1,dev_server:8080",
        },
}

    driver = uc.Chrome(
            service=ser,
            options=options,
            seleniumwire_options=sw_options
)
0 Answers
Related