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

WSL环境下Geckodriver出现readyState为'interactive'页面加载报错问题

问题修复方案

根因说明

该报错并非Firefox与geckodriver版本不匹配导致,核心问题是seleniumwire依赖的cryptography包版本过旧(v2.8),与当前WSL环境的OpenSSL、Python 3.8版本不兼容,触发AttributeError: module 'lib' has no attribute 'SSL_CTX_get0_param'错误,导致seleniumwire的SSL代理注入失效,最终触发Firefox连接重置报错。

修复步骤

  • 首先卸载旧版本的冲突依赖,避免残留版本干扰
pip3 uninstall -y cryptography seleniumwire
  • 安装适配当前环境的依赖版本,优先选择与Python 3.8兼容的稳定版
# 先安装系统编译依赖(若安装cryptography时报错再执行)
sudo apt update && sudo apt install -y build-essential libssl-dev libffi-dev python3-dev
# 安装指定版本的依赖包
pip3 install cryptography==38.0.4 seleniumwire==5.1.0

可选启动参数对齐(解决新旧环境Firefox启动指令差异问题)

你可以在代码中手动配置Firefox启动参数,对齐旧环境的运行配置,同时消除日志中的无关报错:

from seleniumwire import webdriver

class Foo:
    def __init__(self):
        self.web_options = webdriver.FirefoxOptions()
        # 对齐旧环境启动参数
        self.web_options.add_argument("-foreground")
        self.web_options.add_argument("--headless")
        self.web_options.add_argument("-no-remote")
        # 关闭GPU渲染,规避WSL环境的图形渲染报错
        self.web_options.add_argument("--disable-gpu")
        self.web_options.add_argument("--disable-dev-shm-usage")
        self.driver = webdriver.Firefox(options=self.web_options)
    
    def bar(self):
        self.driver.get("https://xkcd.com")
        print(self.driver.current_url)

Foo().bar()

验证方案

运行上述最小复现代码,若能正常输出页面URL、无连接重置报错,再接入生产爬虫代码验证即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 09:48:02