求助:运行Selenium时Firefox出现SEC_ERROR_UNKNOWN_ISSUER错误的解决方法
Hey there! Let's work through that SSL certificate error you're hitting in Firefox while running your Selenium script. I've helped plenty of new devs with this exact setup, so here's what you can try:
First, a quick breakdown: That SEC_ERROR_UNKNOWN_ISSUER message means Firefox doesn't trust the SSL certificate of the site you're trying to access, and Selenium's default Firefox driver is enforcing strict certificate checks. We can fix this a couple of ways—let's start with the simplest code-based fix, then cover a more secure option if you trust the site.
1. Disable certificate checks in your Selenium code
This is the fastest way to get past the error. We'll use FirefoxOptions to tell the driver to ignore SSL certificate warnings. Update your code like this:
from selenium import webdriver from selenium.webdriver.firefox.options import Options # Keep all your existing imports (WebDriverWait, etc.) # Set up Firefox options to bypass SSL checks firefox_options = Options() firefox_options.add_argument("--ignore-certificate-errors") firefox_options.add_argument("--ignore-ssl-errors") # Initialize the driver with these options driver = webdriver.Firefox(options=firefox_options) # Rest of your code goes here...
Important note for your setup:
Since you're using Selenium 3.11.0 and Firefox 59.0.1, make sure you have the correct GeckoDriver version (v0.20.1 works best for this Firefox release). If you haven't set up GeckoDriver yet:
- Download the Mac version of GeckoDriver
- Either place it in a directory in your system PATH (like
/usr/local/bin), or specify its path directly when initializing the driver:driver = webdriver.Firefox( executable_path="/path/to/your/geckodriver", options=firefox_options )
2. Add the certificate to Firefox's trusted store (more secure)
If the site is one you know and trust, you can manually add its SSL certificate to your Firefox profile so Selenium uses that trusted profile. Here's how:
- Open Firefox normally (not via Selenium) and go to the site giving the error
- On the error page, click Advanced > Add Exception...
- Follow the prompts to confirm and save the certificate exception
- Now, tell Selenium to load your default Firefox profile (which includes the trusted certificate):
To find your profile path: Open Firefox, go tofirefox_options = Options() # Replace with your actual profile path profile_path = "/Users/YourUsername/Library/Application Support/Firefox/Profiles/your-profile-folder" firefox_options.profile = webdriver.FirefoxProfile(profile_path) driver = webdriver.Firefox(options=firefox_options)about:profiles, look for the "Root Directory" of your default profile.
Quick troubleshooting checks
- Restart your terminal/IDE after changing PATH or driver settings—sometimes changes don't take effect until you do this
- Double-check that your GeckoDriver permissions are set to executable: Run
chmod +x /path/to/geckodriverin terminal to ensure it can be launched.
Hope these steps get you up and running smoothly! If you run into any issues with the code or profile setup, just let me know.
内容的提问来源于stack exchange,提问作者jms

