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

Selenium配合Chrome使用HTTPS代理时报错ERR_PROXY_CONNECTION_FAILED问题咨询

问题根因及解决方案

1. 最高发原因:免费代理本身无效

免费代理节点存活时间通常只有几分钟到几小时,且很多标注支持HTTPS的节点实际无法转发HTTPS请求,或端口已被屏蔽。

  • 验证方法:本地执行curl命令验证代理可用性:curl -x <host>:<port> https://www.google.com -I,只有返回200状态码的代理才是可正常使用的。

2. 代理配置格式错误

你当前的proxystring仅配置了host:port格式,Chrome需要明确指定代理协议前缀,否则会默认按HTTP代理处理:

  • HTTPS代理需写为https://<host>:<port>
  • HTTP代理需写为http://<host>:<port>
  • SOCKS5代理需写为socks5://<host>:<port>

3. 代码冗余错误

  • 你代码中的UserAgent.random写法错误,缺少实例化步骤,实际应为UserAgent().random,错误的UA生成逻辑可能触发代理节点的反爬策略直接拒连。
  • marionette是Firefox驱动的专属配置项,Chrome驱动不识别该参数,多余配置可能引发启动参数冲突。
  • AcceptSslCerts配置在高版本Chrome中已废弃,需通过ChromeOptions添加忽略证书错误的参数替代。

4. 修正后可用参考代码

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from fake_useragent import UserAgent

# 此处替换为带协议前缀的代理地址
proxystring = "http://替换为你的代理host:替换为你的代理port"

options = webdriver.ChromeOptions()
useragent = UserAgent().random

options.add_argument(f"--user-agent={useragent}")
options.add_argument("--window-size=1920,1080")
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_experimental_option('useAutomationExtension', False)
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_argument(f"--proxy-server={proxystring}")
# 新增SSL证书忽略配置
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')

capabilities = DesiredCapabilities.CHROME.copy()
driver = webdriver.Chrome(options=options, desired_capabilities=capabilities)

如果验证代理本身可用、修改配置后仍无法连接,可尝试用selenium-wire库替代原生配置,该库对代理的兼容性更高,支持需要用户名密码认证的代理场景。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 06:48:02