DrissionPage icon indicating copy to clipboard operation
DrissionPage copied to clipboard

How do you proxy with auth:password. now its does not work

Open saroar opened this issue 1 year ago • 15 comments

        print("Starting initialize_browser...")

        # Set the path to the browser executable
        browser_path = r"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"

        # Create ChromiumOptions object
        options = ChromiumOptions()
        options.set_argument('--incognito')
        options.set_argument('--no-sandbox')

        # proxy_options = {
        #     'proxy': {
        #         'http': f'{self.proxy_string}',
        #         'https': f'{self.proxy_string}'
        #     }
        # }

        # Set paths in ChromiumOptions
        options.set_paths(browser_path=browser_path)
        options.set_proxy(self.proxy_string)


        # Create ChromiumPage with ChromiumOptions
        self.driver = ChromiumPage(addr_driver_opts=options)

        # Navigate to the specified URL
        self.driver.get('https://ipleak.net')
Screenshot 2023-11-30 at 11 48 34

saroar avatar Nov 30 '23 11:11 saroar

I am facing the same problem

rubensm33 avatar Nov 30 '23 12:11 rubensm33

Hello Guys! I have the same problem....

AFrantsevich avatar Dec 01 '23 10:12 AFrantsevich

是的,目前不支持带用户名密码的代理,你可以用插件实现这个功能。

g1879 avatar Dec 12 '23 16:12 g1879

https://github.com/Smartproxy/Selenium-proxy-authentication

This works perfectly fine for me, make sure to unzip the zip file created!

Berthouille avatar Dec 12 '23 21:12 Berthouille

"Make sure to unzip the file created".

I changed the end of the code to the following so as to not create a zip:


    directory_name = "your_directory"

    if not os.path.exists(directory_name):
        os.makedirs(directory_name)

    manifest_path = os.path.join(directory_name, "manifest.json")
    background_path = os.path.join(directory_name, "background.js")

    with open(manifest_path, 'w') as manifest_file:
        manifest_file.write(manifest_json)

    with open(background_path, 'w') as background_file:
        background_file.write(background_js)

Berthouille avatar Dec 13 '23 09:12 Berthouille

Add this in your python code once the js and json file are created.

options=ChromiumOptions()
options.add_extension(directory_name)

Berthouille avatar Dec 13 '23 11:12 Berthouille

I do not understand your problem, here is my full code.

import os

def proxies(username : str, password : str, endpoint : str, port : str):
    manifest_json = """
    {
        "version": "1.0.0",
        "manifest_version": 2,
        "name": "Proxies",
        "permissions": [
            "proxy",
            "tabs",
            "unlimitedStorage",
            "storage",
            "<all_urls>",
            "webRequest",
            "webRequestBlocking"
        ],
        "background": {
            "scripts": ["background.js"]
        },
        "minimum_chrome_version":"22.0.0"
    }
    """

    background_js = """
    var config = {
            mode: "fixed_servers",
            rules: {
              singleProxy: {
                scheme: "http",
                host: "%s",
                port: parseInt(%s)
              },
              bypassList: ["localhost"]
            }
          };

    chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});

    function callbackFn(details) {
        return {
            authCredentials: {
                username: "%s",
                password: "%s"
            }
        };
    }

    chrome.webRequest.onAuthRequired.addListener(
                callbackFn,
                {urls: ["<all_urls>"]},
                ['blocking']
    );
    """ % (endpoint, port, username, password)

    directory_name = "your_directory"

    if not os.path.exists(directory_name):
        os.makedirs(directory_name)

    manifest_path = os.path.join(directory_name, "manifest.json")
    background_path = os.path.join(directory_name, "background.js")

    with open(manifest_path, 'w') as manifest_file:
        manifest_file.write(manifest_json)

    with open(background_path, 'w') as background_file:
        background_file.write(background_js)

Create the directory by calling

proxies(username, password, endpoint, port)

And then

options=ChromiumOptions()
options.add_extension(directory_name)

Berthouille avatar Dec 13 '23 12:12 Berthouille

I do not understand your problem, here is my full code.

import os

def proxies(username : str, password : str, endpoint : str, port : str):
    manifest_json = """
    {
        "version": "1.0.0",
        "manifest_version": 2,
        "name": "Proxies",
        "permissions": [
            "proxy",
            "tabs",
            "unlimitedStorage",
            "storage",
            "<all_urls>",
            "webRequest",
            "webRequestBlocking"
        ],
        "background": {
            "scripts": ["background.js"]
        },
        "minimum_chrome_version":"22.0.0"
    }
    """

    background_js = """
    var config = {
            mode: "fixed_servers",
            rules: {
              singleProxy: {
                scheme: "http",
                host: "%s",
                port: parseInt(%s)
              },
              bypassList: ["localhost"]
            }
          };

    chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});

    function callbackFn(details) {
        return {
            authCredentials: {
                username: "%s",
                password: "%s"
            }
        };
    }

    chrome.webRequest.onAuthRequired.addListener(
                callbackFn,
                {urls: ["<all_urls>"]},
                ['blocking']
    );
    """ % (endpoint, port, username, password)

    directory_name = "your_directory"

    if not os.path.exists(directory_name):
        os.makedirs(directory_name)

    manifest_path = os.path.join(directory_name, "manifest.json")
    background_path = os.path.join(directory_name, "background.js")

    with open(manifest_path, 'w') as manifest_file:
        manifest_file.write(manifest_json)

    with open(background_path, 'w') as background_file:
        background_file.write(background_js)

Create the directory by calling

proxies(username, password, endpoint, port)

And then

options=ChromiumOptions()
options.add_extension(directory_name)

hi How should I choose the default mode? Is it still the same as before?

w5d1xixi avatar Jan 18 '24 22:01 w5d1xixi

https://github.com/Smartproxy/Selenium-proxy-authentication

This works perfectly fine for me, make sure to unzip the zip file created!

Hi, thank you! It's works good on Windows, but unfortunately on Linux server, with the same code, the same library, it does not using proxy at all... Maybe you know how to fix it?

Thanks in advance!

MrHerben avatar Feb 03 '24 23:02 MrHerben

Its not working!

SuperA001 avatar Mar 16 '24 19:03 SuperA001

What version of Chrome are you using?

SuperA001 avatar Mar 16 '24 19:03 SuperA001

Its not working!

Did you fix your problem?

ma1lor avatar Apr 10 '24 12:04 ma1lor

https://github.com/Smartproxy/Selenium-proxy-authentication This works perfectly fine for me, make sure to unzip the zip file created!

Hi, thank you! It's works good on Windows, but unfortunately on Linux server, with the same code, the same library, it does not using proxy at all... Maybe you know how to fix it?

Thanks in advance!

It doesn't work under Linux, have you solved this problem?

arengz avatar Aug 05 '24 10:08 arengz