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

Docker中使用Playwright Python遇SEC_ERROR_UNKNOWN_ISSUER求助

解决Playwright访问网页时SEC_ERROR_UNKNOWN_ISSUER错误的方法

问题说明

运行以下代码时触发SEC_ERROR_UNKNOWN_ISSUER错误:

from playwright.sync_api import sync_playwright
pw = sync_playwright().start()
firefox = pw.firefox.launch(headless=True)
context=firefox.new_context()
page= context.new_page()

page.goto("http://www.uaf.cl/prensa/sanciones_new.aspx")

已尝试在context中设置忽略HTTPS错误但未生效,运行环境为装有update-ca-certificates的Docker容器。

可行解决方案

  • 正确配置忽略HTTPS错误参数:确保创建context时传入下划线分隔的ignore_https_errors=True参数,修改后代码如下:
from playwright.sync_api import sync_playwright

with sync_playwright() as pw:
    firefox = pw.firefox.launch(headless=True)
    context = firefox.new_context(ignore_https_errors=True)
    page = context.new_page()
    page.goto("http://www.uaf.cl/prensa/sanciones_new.aspx")
    # 执行后续操作
    context.close()
    firefox.close()
  • 处理HTTP跳转HTTPS场景:目标网站可能自动从HTTP跳转至HTTPS,此时ignore_https_errors会对跳转后的HTTPS链接生效。
  • Docker环境额外参数配置:若上述方法无效,可在启动Firefox时添加命令行参数强制忽略证书错误,结合context参数使用:
firefox = pw.firefox.launch(
    headless=True,
    args=["--ignore-certificate-errors"]
)
context = firefox.new_context(ignore_https_errors=True)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 15:35:28