Selenium-wire调用Firefox出现SEC_ERROR_UNKNOWN_ISSUER报错如何解决
Selenium-wire调用Firefox出现SEC_ERROR_UNKNOWN_ISSUER错误修复方案
错误原因
Selenium-wire需要作为中间代理拦截HTTPS请求,默认使用自签证书解密流量,Firefox未信任该证书且对应站点的安全策略隐藏了手动接受风险的选项,因此直接抛出证书错误。
修复步骤
按优先级依次尝试以下方案即可:
- 方案1:调整Firefox启动参数,自动跳过证书校验
替换你的代码为以下内容,对应路径和访问地址自行修改即可:
from seleniumwire import webdriver from selenium.webdriver.firefox.options import Options firefox_options = Options() # 全局忽略证书错误 firefox_options.add_argument('--ignore-certificate-errors') # 调整证书校验规则 firefox_options.set_preference('security.cert_pinning.enforcement_level', 0) firefox_options.set_preference('security.enterprise_roots.enabled', True) firefox_options.set_preference('browser.ssl_override_behavior', 2) # 加载你原有的自定义Profile profile = webdriver.FirefoxProfile(r'path\to\profile') # Selenium-wire 配置关闭SSL校验 seleniumwire_config = { 'verify_ssl': False, 'suppress_connection_errors': True } driver = webdriver.Firefox( firefox_profile=profile, options=firefox_options, seleniumwire_options=seleniumwire_config ) driver.get("你的目标访问URL")
- 方案2:手动导入Selenium-wire根证书到自定义Profile
如果方案1不生效,执行以下操作将Selenium-wire的自签证书加入你使用的Firefox Profile的信任列表:
- 找到Selenium-wire的根证书,默认路径为Python安装目录下的
Lib\site-packages\seleniumwire\ca.crt - 正常打开你自定义路径的Firefox Profile,地址栏输入
about:preferences#privacy进入隐私设置页 - 下拉到「安全」分类,点击「查看证书」按钮,切换到「证书机构」标签,选择「导入」,选中刚才找到的ca.crt文件
- 勾选「信任该CA以标识网站」,确认保存后关闭浏览器,再运行你的原有代码即可
- 方案3:手动配置固定代理端口,避免Selenium-wire自动配置代理冲突
如果以上两个方案都未生效,指定固定代理端口手动配置给Firefox,避免自动代理配置失效:
from seleniumwire import webdriver from selenium.webdriver.firefox.options import Options firefox_options = Options() firefox_options.add_argument('--ignore-certificate-errors') firefox_options.set_preference('security.cert_pinning.enforcement_level', 0) # 手动配置代理信息 firefox_options.set_preference('network.proxy.type', 1) firefox_options.set_preference('network.proxy.http', '127.0.0.1') firefox_options.set_preference('network.proxy.http_port', 8087) firefox_options.set_preference('network.proxy.ssl', '127.0.0.1') firefox_options.set_preference('network.proxy.ssl_port', 8087) firefox_options.set_preference('network.proxy.no_proxies_on', 'localhost, 127.0.0.1') profile = webdriver.FirefoxProfile(r'path\to\profile') # Selenium-wire指定固定代理端口 seleniumwire_config = { 'port': 8087, 'verify_ssl': False, 'suppress_connection_errors': True } driver = webdriver.Firefox( firefox_profile=profile, options=firefox_options, seleniumwire_options=seleniumwire_config ) driver.get("你的目标访问URL")
内容的提问来源于stack exchange,提问作者RLU
相关产品推荐
相关产品推荐

