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

时间:2018-12-23 09:28:10

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

我正在使用使用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)

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

3 个答案:

答案 0 :(得分:1)

尽管您看到的错误是:

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: session deleted because of page crash from tab crashed,此问题可以通过以下任一解决方案来解决:

  • 添加以下chrome_options

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

  • 一个例子:

    sudo mount -t tmpfs -o rw,nosuid,nodev,noexec,relatime,size=512M tmpfs /dev/shm
    
  • 如果您使用-v /dev/shm:/dev/shm选项共享 host /dev/shm

  • ,它也可以工作
  • 使其生效的另一种方法是将chrome_options添加为 --disable-dev-shm-usage 。这将强制Chrome使用/tmp目录。尽管这会减慢执行速度,因为将使用磁盘而不是内存。

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

从标签页崩溃

从选项卡中崩溃是与 Chromium团队进行的WIP( Work In Progress ),现在已经有一段时间了,这与 Linux有关尝试始终将/ dev / shm用于不可执行的内存。这里是参考:


参考

您可以在org.openqa.selenium.SessionNotCreatedException: session not created exception from tab crashed error when executing from Jenkins CI server

中找到详细的讨论

答案 1 :(得分:1)

我的 Ubuntu 服务器出现以下错误:

<块引用>

selenium.common.exceptions.WebDriverException:消息:未知错误: 由于选项卡崩溃的页面崩溃而删除会话(会话 信息:无头镀铬 = 86.0.4240.111)(驱动程序信息: 铬驱动程序 = 2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),平台=Linux 5.4.0-1029-aws x86_64)

事实证明错误的原因是服务器上磁盘空间不足,解决方案是扩展我的磁盘空间。您可以查看this question了解更多信息。

答案 2 :(得分:0)

如果有人在使用 docker 容器时遇到这个问题:

在创建容器时使用标志 --shm-size=2g 并且错误消失了。 此标志使容器使用主机的共享内存。

示例

$ docker run -d --net gridNet2020 --shm-size="2g" -e SE_OPTS="-browser applicationName=zChromeNodePdf30,browserName=chrome,maxInstances=1,version=78.0_debug_pdf" -e HUB_HOST=selenium-hub-3.141.59 -P -p 5700:5555 --name zChromeNodePdf30 -v /var/lib/docker/sharedFolder:/home/seluser/Downloads selenium/node-chrome:3.141.59-xenon

来源:https://github.com/SeleniumHQ/docker-selenium