Selenium&Heroku:urllib3.exceptions.ProtocolError:('Connection aborted.',ConnectionResetError(104,'peer reset by peer'))

mad*_*tyn 8 selenium heroku python-3.x selenium-chromedriver buildpack

建立:

  • :3.141.0
  • python:3.6.7
  • heroku-stack:heroku-18
  • headless-chrome:v71.0.3578.80 buildpack安装
  • chromedriver:安装了buildpack v2.44.609551

在heroku中使用selenium时出现此错误:

urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
Run Code Online (Sandbox Code Playgroud)

我用Google搜索但没有运气.错误发生在此代码的最后一行.


from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

UA = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36' \
     '(KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'
DRIVER_PATH = '/app/.chromedriver/bin/chromedriver'

chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = '/app/.apt/usr/bin/google-chrome'
chrome_options.add_argument(f'--user-agent={UA}')
chrome_options.add_argument(f'--proxy-server=http://my_private_proxy.com:my_port')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')

chrome = webdriver.Chrome(executable_path=DRIVER_PATH, options=options)
Run Code Online (Sandbox Code Playgroud)

Deb*_*anB 3

这个错误信息...

urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
Run Code Online (Sandbox Code Playgroud)

...意味着无头模式下的ChromeDriver无法启动/生成新的WebBrowser(即Chrome 浏览器会话)。

有关您正在使用的二进制文件版本的一些信息将帮助我们更好地分析错误。然而,由于以下几个原因,可能会出现urllib3的此问题:

在 Linux 或 macOS 上不再需要此标志。一旦 SwiftShader 在 Windows 上无头模式下断言失败得到修复,它在 Windows 上就变得不必要了。

解决方案

  • 将ChromeDriver升级到当前ChromeDriver v2.44级别。
  • Chrome版本保持在Chrome v69-71级别之间。(根据 ChromeDriver v2.44 发行说明
  • 通过IDE清理项目工作区并仅使用所需的依赖项重建项目。
  • 如果您的基本Web 客户端版本太旧,请将其卸载并安装最新的 GA 和发布版本的Web 客户端
  • 重新启动系统
  • 执行你的@Test.


归档时间:

查看次数:

970 次

最近记录:

6 年,10 月 前