【问题标题】:Selenium & Heroku: urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))Selenium & Heroku: urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
【发布时间】:2019-04-30 12:06:51
【问题描述】:

设置:

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

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

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

我用谷歌搜索但没有运气。错误发生在这段代码的最后一行。


代码

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)

【问题讨论】:

    标签: python-3.x selenium heroku selenium-chromedriver buildpack


    【解决方案1】:

    此错误消息...

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

    ...暗示 Headless 模式下的 ChromeDriver 无法启动/生成新的 WebBrowserChrome 浏览器 会话。

    有关您正在使用的二进制文件版本的一些信息将有助于我们以更好的方式分析错误。但是,urllib3的这个问题可以被观察到,原因如下:

    在 Linux 或 macOS 上不再需要此标志。 SwiftShader fails an assert on Windows in headless mode 得到修复后,Windows 上将不再需要它。

    解决方案

    • ChromeDriver 升级到当前的ChromeDriver v2.44 级别。
    • Chrome 版本保持在 Chrome v69-71 级别之间。 (as per ChromeDriver v2.44 release notes)
    • 清理你的项目工作区通过你的IDE重建你的项目只需要依赖。
    • 如果您的基本 Web 客户端 版本太旧,请卸载它并安装最新的 GA 和发布版本的 Web 客户端
    • 进行系统重启
    • 执行您的@Test

    【讨论】:

    • Heroku 是一个云平台,即我用作服务器的服务。我在帖子中更新了 chromedriver 的版本。我不知道如何从服务器获取无头版本,但由 Heroku 提供,必须非常现代。我不能在 Heroku 中做 IDE 的事情,但我正在做你在源代码中告诉我的更改,检查二进制和驱动程序路径并重新启动 Heroku 服务器。也不知道如何处理 @Test 的事情。同时我也在努力,谢谢。 :-)
    • 看来你的一些建议确实奏效了。现在我遇到了一个不同的 SessionNotCreatedException:“会话不是从崩溃选项卡创建的”。我现在正在解决这个问题。谢谢。
    • @madtyn 对于错误 SessionNotCreatedException: "Session not created from crash tab" 检查我在讨论 org.openqa.selenium.SessionNotCreatedException: session not created exception from tab crashed error when executing from Jenkins CI server 中的回答中的 Update 部分
    猜你喜欢
    • 2019-02-02
    • 1970-01-01
    • 2019-09-14
    • 1970-01-01
    • 1970-01-01
    • 2020-01-15
    • 1970-01-01
    • 1970-01-01
    • 2018-07-28
    相关资源
    最近更新 更多