close

How to set proxy authentication (user & password) using Python + Selenium

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to set proxy authentication (user & password) using Python + Selenium in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to set proxy authentication (user & password) using Python + Selenium?

  1. How to set proxy authentication (user & password) using Python + Selenium?

    There are already some extensions that will do the job. For instance: Close Proxy Authentication

  2. set proxy authentication (user & password) using Python + Selenium

    There are already some extensions that will do the job. For instance: Close Proxy Authentication

Method 1

In addition to running Firefox with a profile which has the credentials saved. You can do it loading an extension that writes in the loginTextbox and password1Textbox of chrome://global/content/commonDialog.xul (the alert window).

There are already some extensions that will do the job. For instance: Close Proxy Authentication

from selenium import webdriver
from base64 import b64encode

proxy = {'host': HOST, 'port': PORT, 'usr': USER, 'pwd': PASSWD}

fp = webdriver.FirefoxProfile()

fp.add_extension('closeproxy.xpi')
fp.set_preference('network.proxy.type', 1)
fp.set_preference('network.proxy.http', proxy['host'])
fp.set_preference('network.proxy.http_port', int(proxy['port']))
# ... ssl, socks, ftp ...
fp.set_preference('network.proxy.no_proxies_on', 'localhost, 127.0.0.1')

credentials = '{usr}:{pwd}'.format(**proxy)
credentials = b64encode(credentials.encode('ascii')).decode('utf-8')
fp.set_preference('extensions.closeproxyauth.authtoken', credentials)

driver = webdriver.Firefox(fp)

Method 2

In an addition to the answer with extension.

You can also use form filling to dynamically change credentials on your proxy. Just load the extension page, fill the form automatically and click save!

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read