【问题标题】:Selenium script crashed and will no longer work; session not created from tab crashedSelenium 脚本崩溃,将不再工作;未从选项卡创建的会话崩溃
【发布时间】:2020-08-26 18:30:04
【问题描述】:

在处理一些内存问题时,我的脚本被中断,现在它不会重新启动。我收到错误“selenium.common.exceptions.SessionNotCreatedException:消息:未从选项卡创建的会话已崩溃(会话信息:无头 chrome=84.0.4147.135)”

我阅读了一些其他类似的问题 (this one is almost identical),但解决方案无法解决我的问题。

这是我的代码:

from selenium import webdriver

chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument("--headless")
chromeOptions.add_argument("--remote-debugging-port=9222")
chromeOptions.add_argument('--no-sandbox')
chromeOptions.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US',
                        "download.default_directory": download_location,
                        "download.directory_upgrade": True})
webdriver_location = '/usr/bin/chromedriver'

driver = webdriver.Chrome(webdriver_location,options=chromeOptions)

我尝试添加 chromeOptions.add_argument('--disable-dev-shm-usage') 并收到相同的错误。

因为之前的设置运行完美,并且没有进行任何更新,所以我认为任何版本控制都不是问题。我在 Centos 7 服务器上运行。我最初收到 Google Chrome 84 和 Chromedriver 84 的错误。同时升级到 85 时出现同样的错误。

这是完整的错误:

   Traceback (most recent call last):
  File "server_scraper_javascript_v2.py", line 323, in <module>
    driver = webdriver.Chrome(webdriver_location,options=chromeOptions)
  File "/home/education01/scraper/env/lib64/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
    RemoteWebDriver.__init__(
  File "/home/education01/scraper/env/lib64/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/education01/scraper/env/lib64/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/education01/scraper/env/lib64/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/education01/scraper/env/lib64/python3.8/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 tab crashed
  (Session info: headless chrome=84.0.4147.135)

更新: 我没有在没有 Selenium 和 webdriver 的情况下使用 Chromium 的经验,但如果我运行 chrome --headless --disable-gpu --dump-dom https://www.chromestatus.com/,它会失败并且我会收到以下信息:

#
# Fatal error in , line 0
# Fatal process out of memory: Failed to reserve memory for new V8 Isolate
#
#
#
#FailureMessage Object: 0x7ffc0fc7ed50#0 0x5619c34ebdd9 <unknown>
--2020-08-27 10:20:27--  https://clients2.google.com/cr/report
Resolving clients2.google.com (clients2.google.com)... 172.217.165.142, 2607:f8b0:4006:808::200e
Connecting to clients2.google.com (clients2.google.com)|172.217.165.142|:443... connected.
HTTP request sent, awaiting response... [0827/102028.181052:ERROR:headless_shell.cc(391)] Abnormal renderer termination.
200 OK
Length: unspecified [text/plain]
Saving to: ‘/dev/fd/4’


     0K Crash dump id:   80939f7cd5646339 

【问题讨论】:

  • 你试过用version 85的Chrome驱动吗?
  • @MarekPiotrowski 是的,我做了同样的错误。我不会仅仅因为它以前一直在正常工作而考虑升级,但更新没有帮助。
  • 您可以手动打开 Chromium 并毫无问题地导航?
  • 我没有设置任何 GUI,也从未在没有 webdriver 和 Selenium 的情况下使用过 Chromium,所以我不确定最好的测试方法。如果我运行google-chrome --headless --disable-gpu --dump-dom https://www.chromestatus.com/,它确实会失败。我收到“Fatal error in , line 0 # Fatal process out of memory: Failed to reserved memory for new V8 Isolate”。我会将这个添加到问题中。
  • 然后更改您的 ulimit:access.redhat.com/solutions/61334

标签: python selenium selenium-webdriver selenium-chromedriver chromium


【解决方案1】:

我最近遇到了这个问题,我经常调用的脚本正在运行,然后由于相同的“会话不是从选项卡创建”错误而失败。我没有更新 chrome 或 chromedriver,所以我发现的其他解决方案不起作用。我发现问题在于我没有在脚本结束时退出浏览器,所以它们仍然处于活动状态。

我用pgrep chrome检查了chrome的活动pid,发现我有一堆chrome进程正在运行。我用pkill chrome 杀死了他们,这解决了这个问题。我在脚本末尾添加了driver.quit(),以便在完成后终止浏览器。

我不确定这是否能解决您的问题,但您在尝试运行 google-chrome --headless 时遇到的内存错误让我认为这可能与我遇到的问题相同。

【讨论】:

    猜你喜欢
    • 2020-03-29
    • 1970-01-01
    • 2020-06-28
    • 2020-06-25
    • 1970-01-01
    • 2021-10-05
    • 2020-08-13
    • 2018-09-06
    • 2011-10-13
    相关资源
    最近更新 更多