【问题标题】:SessionNotCreatedException: Message: session not created from disconnected: unable to connect to renderer using Chromedriver on Linux Centos 7 ServerSessionNotCreatedException:消息:会话未从断开连接创建:无法在 Linux Centos 7 服务器上使用 Chromedriver 连接到渲染器
【发布时间】:2020-06-03 13:44:33
【问题描述】:

我正在尝试在带有 selenium 和 python 的 Linux Centos 7 服务器上使用 headless chrome。尝试激活驱动程序时出现以下错误:

Traceback (most recent call last):
  File "send_notif_marktplaats.py", line 128, in <module>
    main()
  File "send_notif_marktplaats.py", line 117, in main
    driver = activate_driver()
  File "send_notif_marktplaats.py", line 42, in activate_driver
    driver = webdriver.Chrome(executable_path="/usr/local/bin/chromedriver", chrome_options=optionsChrome)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from disconnected: unable to connect to renderer
  (Session info: headless chrome=80.0.3987.116)

我的版本:

  • Chrome 驱动程序版本 80.0.3987.106
  • 谷歌浏览器 80.0.3987.116

谁能帮帮我?

【问题讨论】:

  • 执行chromedriver和chrome看看是否需要安装一些包。
  • 使用沙盒[0219/114121.573710:ERROR:nacl_helper_linux.cc(308)] NaCl helper process running without a sandbox! Most likely you need to configure your SUID sandbox correctly执行chrome时出现此错误
  • 您为 chrome 浏览器配置了哪些选项?为什么不使用 81 版?它不适用于 80 版。
  • 我现在只使用了无沙盒,但我也尝试了这些:optionsChrome.add_argument("--headless") optionsChrome.add_argument("start-maximized") optionsChrome.add_argument("disable-infobars") optionsChrome.add_argument("--disable-extensions") optionsChrome.add_argument("--disable-gpu") optionsChrome.add_argument("--disable-dev-shm-usage") optionsChrome.add_argument("--no-sandbox")
  • 我会试试81版

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


【解决方案1】:

此错误消息...

selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from disconnected: unable to connect to renderer
  (Session info: headless chrome=80.0.3987.116)

...暗示 ChromeDriver v80.0 无法启动/生成新的浏览上下文,即 Chrome 浏览器 会话。


根据WebDriver 80.0.3987.16 can't open Chrome on Linux@triciac 的讨论更新,ChromeDriver v80.0 的实现按以下顺序查找 Chrome

  1. locations->push_back(base::FilePath("/usr/local/sbin"));
  2. locations->push_back(base::FilePath("/usr/local/bin"));
  3. locations->push_back(base::FilePath("/usr/sbin"));
  4. locations->push_back(base::FilePath("/usr/bin"));
  5. locations->push_back(base::FilePath("/sbin"));
  6. locations->push_back(base::FilePath("/bin"));
  7. 位置->push_back(base::FilePath("/opt/google/chrome")); // 最后尝试使用默认安装位置。

@johnchen,确认Linux上的二分搜索顺序被r708243意外更改了,这是为了更容易配置Chrome二进制文件的名称,但也意外更改了搜索顺序。

ChromeDriver 团队已更新 ChromeDriver 以通过此revision / commit 解决此问题。


解决方案

上述解决方案适用于:


临时解决方案

临时解决方案是使用binary_location 属性,您可以在Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed

中找到详细讨论

【讨论】:

    猜你喜欢
    • 2019-05-17
    • 1970-01-01
    • 2019-03-25
    • 2021-05-05
    • 1970-01-01
    • 2013-05-31
    • 2018-05-04
    相关资源
    最近更新 更多