selenium.common.exceptions.InsecureCertificateException: probably due to HSTS policy


I am trying to open microsoft outlook using selenium firefox, but I get this when the url opens
Connection to has a security policy called HTTP Strict Transport Security (HSTS), which means that Firefox can only connect to it securely. The error I get on terminal is

Traceback (most recent call last):
  File "", line 313, in start_driver
  File "C:UsersIT", line 449, in get
    self.execute(Command.GET, {"url": url})
  File "C:UsersIT", line 440, in execute       
  File "C:UsersIT", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InsecureCertificateException: Message:
[email protected]://remote/content/shared/RemoteError.sys.mjs:8:8
[email protected]://remote/content/shared/webdriver/Errors.sys.mjs:180:5
[email protected]://remote/content/shared/webdriver/Errors.sys.mjs:301:5
[email protected]://remote/content/marionette/navigate.sys.mjs:58:24
[email protected]://remote/content/marionette/navigate.sys.mjs:329:39
[email protected]://gre/modules/EventEmitter.sys.mjs:154:20
[email protected]://remote/content/marionette/actors/MarionetteEventsParent.sys.mjs:35:25

I have tried everything I could find on internet but none solved my problem. The code is

from seleniumwire import webdriver
from import Service
from webdriver_manager.firefox import GeckoDriverManager
from webdriver_manager import utils
import sys

URL = ''
firefox_options = webdriver.FirefoxOptions()
# firefox_options.add_argument('--no-sandbox')
path_to_firefox_profile = "output_files\firefox\xlycfcyp.default-release"
profile = webdriver.FirefoxProfile(path_to_firefox_profile)
profile.set_preference("dom.webdriver.enabled", False)
profile.set_preference('useAutomationExtension', False)
firefox_options.set_preference("general.useragent.override", 'user-agent=Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0')
driver_installation = GeckoDriverManager().install()
service = Service(driver_installation)
if sys.platform == 'win32':
    from subprocess import CREATE_NO_WINDOW
    service.creationflags = CREATE_NO_WINDOW

driver = webdriver.Firefox(options=firefox_options, firefox_profile=profile,


I have tried my best, I hope someone helps me.
The same thing works for gmail. It also has HSTS policy but it is working fine.
Thanks in advance

Asked By: farhan jatt



Set profile attribute accept_untrusted_certs to True as follows:

profile = webdriver.FirefoxProfile(path_to_firefox_profile)
profile.accept_untrusted_certs = True


Additionally, you can also add set the following preferences through an instance of firefox.options as follows:

from selenium.webdriver.firefox.options import Options

options.set_preference("security.mixed_content.block_active_content", false);
options.set_preference("security.mixed_content.block_display_content", true);
Answered By: undetected Selenium

I have found the solution and don’t know the exact reason why this worked. The fix was to set the following preference.

profile.set_preference("security.mixed_content.block_active_content", False)

This tells Firefox to allow mixed content (content that is loaded over both HTTP and HTTPS) on the website.
After this I did not get the Insecure Certificate Error.

Answered By: farhan jatt