【问题标题】:WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium through Python on VPSWebDriverException:消息:未知错误:Chrome 无法启动:通过 VPS 上的 Python 使用 ChromeDriver Chrome 和 Selenium 异常退出
【发布时间】:2019-02-15 18:24:00
【问题描述】:

所以我和这些帖子有完全相同的错误

Selenium 'Chrome failed to start: exited abnormally' error

Unknown error: Chrome failed to start: exited abnormally

我尝试了他们推荐的方法,但没有奏效。

这是我的代码

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(800, 600))
display.start()

options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-extensions')
options.add_argument('--headless')
options.add_argument('--disable-gpu')

driver = webdriver.Chrome(chrome_options=options)
driver.get('http://nytimes.com')
print(driver.title)

driver.close()

这是完整的错误信息

Traceback (most recent call last):
  File "seleniumtest.py", line 13, in <module>
    driver = webdriver.Chrome(chrome_options=options)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.15.0-42-generic x86_64)

我到底做错了什么?我在 digitalocean 上的 ubuntu VPS 上运行它。

【问题讨论】:

  • 如果您已经在无头虚拟显示器中,通常不需要无头 chrome。

标签: python selenium google-chrome selenium-chromedriver google-chrome-headless


【解决方案1】:

此错误消息...

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.15.0-42-generic x86_64)

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

下面将讨论两个不兼容问题。


禁用显卡

Headless Chrome 首次由 Google 团队 发布为 GA(通用可用性) 时,文章 Getting Started with Headless Chrome 提到:

--disable-gpu \                # Temporarily needed if running on Windows.

一个注释被添加为:

现在,如果您在 Windows 上运行,您还需要包含 --disable-gpu 标志。

根据Headless: make --disable-gpu flag unnecessary 的讨论,很明显:

--disable-gpu 标志在 LinuxMac OSX 上不再需要。一旦 bug SwiftShader fails an assert on Windows in headless mode 得到修复,它在 Windows 上也将变得不必要。现在这个问题被标记为fixed,参数--disable-gpu现在应该是多余的了。

注意:您可以在ERROR:gpu_process_transport_factory.cc(1007)-Lost UI shared context : while initializing Chrome browser through ChromeDriver in Headless mode找到详细讨论


但是,您的主要问题是您使用的二进制文件版本之间的不兼容,如下所示:

  • 您正在使用 chromedriver=2.30
  • chromedriver=2.30 的发行说明明确提及以下内容:

支持 Chrome v58-60

  • 我们不知道您的 chrome 版本。假设您使用的是最新的 Chrome 版本之一:
    • Chrome version 71
    • Chrome version 72
    • Chrome version 73

所以 ChromeDriver v2.30Chrome 浏览器 v71-73

之间存在明显的不匹配

解决方案

  • 根据您的 Chrome 浏览器 版本升级 ChromeDriver 相应地遵循以下guidelines
    • 如果您使用的是Chrome 73版,则需要下载ChromeDriver 73.0.3683.20
    • 如果您使用的是 Chrome 版本 72,则需要下载 ChromeDriver 2.46 或 ChromeDriver 72.0.3626.69
    • 如果您使用的是 Chrome 版本 71,则需要下载 ChromeDriver 2.46 或 ChromeDriver 71.0.3578.137
    • 对于旧版本的 Chrome,请参阅 this discussion 了解支持它的 ChromeDriver 版本。

参考文献

您可以在以下位置找到一些相关讨论:

【讨论】:

  • 谢谢!!就是这样——我有一个旧版本的 chromedriver。不知道我是如何设法安装旧版本的,因为我今天安装了它,但没关系。现在可以使用了!
  • 非常感谢!!
【解决方案2】:

您尚未提供浏览器的版本,但 chromedriver 2.30 已经相当旧了 - 大约 2017 年 6 月; Chrome 那时是 59 版,现在是 72 版。 (yes, I checked, it's not like I know their release history by heart ?)

我建议将其升级到最新版本 - 或与您安装的浏览器匹配的版本。

【讨论】:

  • 是的,这就是问题所在,我升级到了 2.46 并且成功了!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-06-17
  • 1970-01-01
  • 2020-11-01
  • 2020-05-21
  • 2017-09-07
  • 1970-01-01
  • 2019-10-22
相关资源
最近更新 更多