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

mas*_*f85 8 python selenium google-chrome selenium-chromedriver selenium-webdriver

我正在使用使用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)
Run Code Online (Sandbox Code Playgroud)

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

小智 24

如果有人在使用 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
Run Code Online (Sandbox Code Playgroud)

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

  • 在 `docker-compose.yml` 中,可以通过每个服务的 `shm_size: 2g` 来指定。/sf/answers/3965856401/ (7认同)

Deb*_*anB 14

虽然您看到的错误为:

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'
Run Code Online (Sandbox Code Playgroud)

主要的例外是:

selenium.common.exceptions.WebDriverException: Message: unknown error: session deleted because of page crash
from unknown error: cannot determine loading status
from tab crashed
Run Code Online (Sandbox Code Playgroud)

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


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

  • 添加以下内容chrome_options

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

  • 一个例子:

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

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

    chrome_options.add_argument('--disable-dev-shm-usage')        
    
    Run Code Online (Sandbox Code Playgroud)

从标签页崩溃

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


参考

您可以在org.openqa.selenium.SessionNotCreatedException中找到详细的讨论:从Jenkins CI服务器执行时,会话未从选项卡崩溃的错误中创建异常

  • 使用 chrome_options.add_argument('--disable-dev-shm-usage') 参数结束了我花了 5 个小时修复选项卡崩溃的搜索。非常感谢您的分享! (4认同)
  • options.addArguments("--disable-dev-shm-usage") 有效! (4认同)
  • 我有同样的错误,并按照建议执行了所有操作,但没有解决我的问题,错误仍然存​​在。有什么不同的建议吗? (3认同)
  • 这个解决方案解决了我的问题。我在 docker 容器内并使用 `-v /dev/shm:/dev/shm` 解决了问题 (3认同)
  • 这是我第二次重新审视这个 SO 解决方案。归根结底,添加这些选项确实可以降低“无法确定加载状态”和“选项卡崩溃”的可能性,但有时我仍然会遇到这种情况,但这种情况很少见,比如 10-20 中就有 1 个测试我只是重新尝试测试来处理它。我正在使用最新的 chrome 和 selenium,所以真的希望这个问题能够得到很好的调查。好吧,也许我的“/dev/shm”有时对于硒来说太小,即使有“--disable-dev-shm-usage”。 (2认同)

归档时间:

查看次数:

6743 次

最近记录:

6 年,10 月 前