当前位置: 首页 > 面试题库 >

未知错误:会话因页面崩溃而从未知错误中删除:无法通过ChromeDriver Selenium崩溃的选项卡确定加载状态

哈翔
2023-03-14
问题内容

我正在使用使用Python和Selenium的InstaPy。我每个Cron都会启动脚本,并且有时会崩溃。所以它确实是不规则的,有时运行得很好。我也已经在GitHub
Repo上发布了消息,但是在那儿没有得到答案,所以我现在在这里问是否有人知道为什么。

这是一台数字海洋ubuntu服务器,我在无头模式下使用它。驱动程序版本在日志中可见。这是错误消息:

ERROR [2018-12-10 09:53:54] [user]  Error occurred while deleting cookies from web browser!
b'Message: invalid session id\n  (Driver info: chromedriver=2.44.609551 (5d576e9a44fe4c5b6a07e568f1ebc753f1214634),platform=Linux 4.15.0-42-generic x86_64)\n'
Traceback (most recent call last):
  File "/root/InstaPy/instapy/util.py", line 1410, in smart_run
    yield
  File "./my_config.py", line 43, in <module>
    session.follow_user_followers(['xxxx','xxxx','xxxx','xxxx'], amount=100, randomize=True, interact=True)
  File "/root/InstaPy/instapy/instapy.py", line 2907, in follow_user_followers
    self.logfolder)
  File "/root/InstaPy/instapy/unfollow_util.py", line 883, in get_given_user_followers
    channel, jumps, logger, logfolder)
  File "/root/InstaPy/instapy/unfollow_util.py", line 722, in get_users_through_dialog
    person_list = dialog_username_extractor(buttons)
  File "/root/InstaPy/instapy/unfollow_util.py", line 747, in dialog_username_extractor
    person_list.append(person.find_element_by_xpath("../../../*")
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 351, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 659, in find_element
    {"using": by, "value": value})['value']
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/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: session deleted because of page crash
from unknown error: cannot determine loading status
from tab crashed
  (Session info: headless chrome=70.0.3538.110)
  (Driver info: chromedriver=2.44.609551 (5d576e9a44fe4c5b6a07e568f1ebc753f1214634),platform=Linux 4.15.0-42-generic x86_64)

During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
  File "/root/InstaPy/instapy/instapy.py", line 3845, in end
    self.browser.delete_all_cookies()
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 878, in delete_all_cookies
    self.execute(Command.DELETE_ALL_COOKIES)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
  (Session info: headless chrome=71.0.3578.80)
  (Driver info: chromedriver=2.44.609551 (5d576e9a44fe4c5b6a07e568f1ebc753f1214634),platform=Linux 4.15.0-42-generic x86_64)

知道原因可能是什么以及如何解决?


问题答案:

虽然您看到的错误为:

Error occurred while deleting cookies from web browser!
b'Message: invalid session id\n  (Driver info: chromedriver=2.44.609551 (5d576e9a44fe4c5b6a07e568f1ebc753f1214634),platform=Linux 4.15.0-42-generic x86_64)\n'

主要的例外是:

selenium.common.exceptions.WebDriverException: Message: unknown error: session deleted because of page crash
from unknown error: cannot determine loading status
from tab crashed

您的代码试用会为我们提供一些出了什么问题的线索。

有多种解决此问题的方法。但是,按照UnknownError:由于标签页崩溃导致会话删除,会话可以通过以下解决方案之一解决:

  • 添加以下内容chrome_options

    chrome_options.add_argument('--no-sandbox')
    
  • 由于太小,Chrome似乎在某些页面的Docker容器中崩溃/dev/shm。因此,您可能必须修复较小的/dev/shm尺寸。

  • 一个例子:

    sudo mount -t tmpfs -o rw,nosuid,nodev,noexec,relatime,size=512M tmpfs /dev/shm
    
  • 如果您使用-v /dev/shm:/dev/shm选项共享 主机, 它也可以工作 __/dev/shm

  • 使它起作用的另一种方法是将chrome_optionsas 添加 --disable-dev-shm-usage 。这将迫使Chrome使用该/tmp目录。尽管这会减慢执行速度,因为将使用磁盘而不是内存。

    chrome_options.add_argument('--disable-dev-shm-usage')
    

从标签页崩溃

从标签崩溃的Chromium团队 进行WIP( 工作进行中 )了相当长时间了,这与 Linux试图始终使用/ dev /
shm作为不可执行内存有关
。以下是参考资料:

  • Linux:Chrome / Chromium SIGBUS / Aw,Snap!在小型/ dev / shm上
  • 当/ dev / shm太小且无法覆盖位置时,Chrome崩溃/无法加载
  • 根据Comment61#Issue 736452,此修复程序似乎已随 Chrome v65.0.3299.6 一起 发布


 类似资料:
  • 注意:我的问题被关闭之前,我尝试了这里提到的解决方案-未知错误:会话删除,因为页面崩溃从未知错误:无法确定加载状态从标签崩溃与ChromeDriver硒-添加这些选项-options.add参数("--disable-dev-shm-用法");options.add参数("--no-沙盒"); -- 我仍然看到的问题 在selenium网格中运行时,在某些情况下,单个测试会出现以下错误: 方法1:

  • 我正在使用InstaPy,它使用Python和Selenium。我按Cron启动脚本,有时会崩溃。所以它是非常不规则的,有时它运行良好。我已经在GitHub Repo上发布了,但没有得到回复,所以我现在在这里问,是否有人知道为什么。 这是一个数字海洋ubuntu服务器,我在无头模式下使用它。驱动程序版本在日志上可见。以下是错误消息: 你知道原因是什么,怎么解决吗? 谢谢你的意见。http://tr

  • 问题可能是内存使用。页面开始变得非常慢,在某个时候出现以下错误消息 下面是一些我浏览过的类似问题的链接,我尝试添加选项,但不起作用。其他一些技巧真的让我困惑,所以我希望有人能在这里帮助我(我对编码很陌生) 以下是我浏览的链接 未知错误:会话被删除,因为选项卡崩溃导致页面崩溃 python linux selenium:无法访问chrome 未知错误:由于未知错误导致页面崩溃,会话被删除:无法从Ch

  • 问题内容: 我正在尝试使用ChromeWebDriver在Chrome上测试我的应用程序,但是每次尝试都会出现以下异常: 在chromedriver.log中,我看到了 我正在使用: 镀铬36 ChromeWebDriver 2.10 Windows 7的 在Process Explorer中,我可以看到chromedriver.exe进程正在运行,但是没有打开任何窗口,几秒钟后,我得到了上面的异

  • 我有这个代码和一个执行中的问题(代码下的描述) 我使用: Ubuntu 14.04.5 LTS 当我创建RemoteWebDriver时,我得到以下错误:异常:未知错误:Chrome无法启动:崩溃 启动selenium服务器的命令 此方案的哪些部分可能是所述错误的原因?

  • 我试图将与一起使用,我为chromedriver到/usr/local/bin的路径创建了一个符号链接,但当我运行 我的错误是 它还会生成一个核心。******,一个包含五个随机数的核心文件点,大小超过200MB。 版本: 有谁能帮我找出问题出在哪里吗?