[Python] Selenium-wire not authenticating proxy when used with user data directory

Discussão em 'Python' iniciado por Stack, Abril 11, 2025.

  1. Stack

    Stack Membro Participativo

    I want to use Selenium-wire to see the requests that are being made to a site with a session. The sessions are coming from a user data directory, which were previously created with seleniumbase and a proxy. The issue is that the user data directory has the proxy attached to it, and selenium-wire can't authenticate the proxy for some reason. It brings up a pop-up that says "The proxy XXX:XXX requires a username and password".

    I have the original proxies saved, with their usernames and passwords. When I manually input the username and password, it works perfectly and the session is valid.

    Here is a snippet of the code:

    options = {
    'proxy': {
    'http': f'http://{user}:{pw}@{ip}:{host}',
    'https': f'https://{user}:{pw}@{ip}:{host}',
    }
    }

    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument(f"--user-data-dir={userDataDir}")

    sb = webdriver.Chrome(seleniumwire_options=options, options=chrome_options)

    sb.set_window_position(10, 10)
    sb.set_window_size(640, 750)

    sb.get("site-here")
    for request in sb.requests:
    print(request)


    exit = input("press enter to exit")
    sb.quit()


    I don't know why it isn't authenticating properly. The credentials work and the proxies work as well. This is happening for every saved session I have.

    I expected the site to open and the proxy to be valid, as well as the session to be valid. If I remove the user data directory, the site loads properly. If I remove the proxy, it still gives me the same error.

    Edit: I got the proxies to work with an extension, but the requests are not showing up. It stays empty even after visiting multiple pages.

    Continue reading...

Compartilhe esta Página