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

WSGI应用中使用Selenium包报错问题求助

解决ImportError: cannot import name 'InvalidArgumentException' from 'selenium.common'

这个问题基本是selenium与undetected-chromedriver版本不兼容导致的——本地Ubuntu环境的版本组合匹配,而CentOS9服务器上的版本错位了。以下是具体解决步骤:

  • 先检查当前安装的版本:

    pip list | grep -E "selenium|undetected-chromedriver"
    

    如果selenium是3.x系列,大概率没有InvalidArgumentException这个异常类——该类是selenium 4.x才引入的,新版本的undetected-chromedriver依赖它。

  • 卸载现有不兼容包,重新安装匹配版本:

    pip uninstall -y selenium undetected-chromedriver
    # 安装经过验证的稳定兼容组合,可根据实际情况调整版本号
    pip install selenium==4.15.2 undetected-chromedriver==3.5.5
    

    或者直接升级到最新兼容版本:

    pip install --upgrade selenium undetected-chromedriver
    
  • 确认CentOS9上的Chrome浏览器版本:
    undetected-chromedriver需要与本地Chrome版本对应,执行命令查看:

    google-chrome --version
    

    如果Chrome版本过旧,先更新它:

    sudo dnf install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
    sudo dnf update google-chrome-stable
    
  • 检查虚拟环境(如果使用的话):
    确保Flask应用运行的虚拟环境和安装包的环境一致,避免全局包与虚拟环境包冲突。激活虚拟环境后再执行安装命令:

    source your_venv/bin/activate
    pip install ...
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 06:47:39