You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Selenium登录报错:Couldn't read tbsCertificate as SEQUENCE

解决ChromeDriver登录时证书解析错误的方案

错误信息

[5064:9952:0514/222545.212:ERROR:cert_issuer_source_aia.cc(34)] Error parsing cert retrieved from AIA (as DER):
ERROR: Couldn't read tbsCertificate as SEQUENCE
ERROR: Failed parsing Certificate

可行解决方案

1. 补充证书忽略参数

现有参数不足以完全跳过证书验证,补充以下参数组合,同时更新capabilities的设置方式(新版本ChromeDriver推荐用options.set_capability替代desired_capabilities):

from selenium import webdriver
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
# 补充证书相关忽略参数
options.add_argument('--allow-running-insecure-content')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
options.add_argument('--allow-insecure-localhost')
# 设置接受不安全证书
options.set_capability('acceptInsecureCerts', True)

# 初始化驱动
driver = webdriver.Chrome(options=options)
driver.get(login_url)

# 后续登录操作不变
username_input = driver.find_element(By.CLASS_NAME, 'tst-login-email-input')
password_input = driver.find_element(By.CLASS_NAME, 'tst-login-password-input')
username_input.send_keys(username)
password_input.send_keys(password)
submit_button = driver.find_element(By.CLASS_NAME, 'tst-login-submit-button')
submit_button.click()

2. 使用导入过网站证书的Chrome配置文件

如果网站使用自签名或私有CA证书,可以手动在Chrome浏览器中导入证书,然后让ChromeDriver复用该配置文件:

  1. 打开Chrome浏览器,导入目标网站的证书(设置→隐私和安全→安全→管理证书→导入)
  2. 找到Chrome用户数据目录:
    • Windows:C:\Users\<你的用户名>\AppData\Local\Google\Chrome\User Data
    • macOS:~/Library/Application Support/Google/Chrome
    • Linux:~/.config/google-chrome
  3. 在代码中指定该目录:
options = webdriver.ChromeOptions()
# 指定用户数据目录
options.add_argument(r'--user-data-dir=C:\Users\YourName\AppData\Local\Google\Chrome\User Data')
# 指定使用默认配置文件(如果有多个配置文件,替换为对应名称)
options.add_argument('--profile-directory=Default')

driver = webdriver.Chrome(options=options)
driver.get(login_url)

3. 切换至Firefox驱动尝试

ChromeDriver对部分异常证书的处理可能存在兼容性问题,换用Firefox的GeckoDriver可能绕过该问题:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By

options = Options()
options.accept_insecure_certs = True

driver = webdriver.Firefox(options=options)
driver.get(login_url)

# 登录操作
username_input = driver.find_element(By.CLASS_NAME, 'tst-login-email-input')
password_input = driver.find_element(By.CLASS_NAME, 'tst-login-password-input')
username_input.send_keys(username)
password_input.send_keys(password)
submit_button = driver.find_element(By.CLASS_NAME, 'tst-login-submit-button')
submit_button.click()

4. 匹配Chrome与ChromeDriver版本

确保ChromeDriver版本与Chrome浏览器版本完全匹配(大版本一致即可),部分新版本的兼容性问题可能在匹配版本后解决。

错误原因说明

该错误是Chrome在尝试从AIA(证书颁发机构信息访问)获取证书链中的上级证书时,解析失败导致的,可能的原因包括:网站证书链不完整、证书格式不符合标准、ChromeDriver对特定证书的解析逻辑存在bug。

内容的提问来源于stack exchange,提问作者stitas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 03:40:23