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

Selenium启动Chrome报错ValueError:连接超时值类型异常

解决Selenium启动Chrome时的ValueError(连接超时类型错误)

问题根源

这个错误主要来自三个方面:

  • 旧版Selenium与新版urllib3不兼容,导致超时参数被错误解析为对象而非数值类型
  • ChromeDriver版本和本地Chrome浏览器版本不匹配,引发启动连接异常
  • Windows路径中的反斜杠未正确转义,驱动路径识别失败

解决方案

方案1:升级Selenium并使用新驱动管理方式(优先推荐)

旧版Selenium的executable_path参数已被弃用,改用Service类更稳定:

  1. 重装适配Python3.7的Selenium版本:
pip uninstall selenium
pip install selenium==3.141.0
  1. 修改代码,处理路径转义并使用Service类:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

# 用原始字符串避免转义问题
driver_path = r"C:\Users\HP\Desktop\webdriver\chromedriver.exe"
service = Service(driver_path)
driver = webdriver.Chrome(service=service)
driver.get("https://www.amazon.in/")

方案2:降级urllib3到兼容版本

如果不想升级Selenium,可降低urllib3版本:

pip install urllib3==1.26.6

方案3:匹配ChromeDriver与Chrome版本

  1. 打开Chrome,输入chrome://version/查看浏览器版本
  2. 下载对应版本的ChromeDriver,替换原路径下的驱动文件

验证

运行修改后的代码,确认Chrome正常启动并加载亚马逊印度站;若仍有问题,关闭所有Chrome进程后重试。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 04:42:04