Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 未知错误:由于未知错误导致的页面崩溃,会话被删除:无法从ChromeDriver Selenium崩溃的选项卡确定加载状态_Python_Selenium_Google Chrome_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

Python 未知错误:由于未知错误导致的页面崩溃,会话被删除:无法从ChromeDriver Selenium崩溃的选项卡确定加载状态

Python 未知错误:由于未知错误导致的页面崩溃,会话被删除:无法从ChromeDriver Selenium崩溃的选项卡确定加载状态,python,selenium,google-chrome,selenium-webdriver,selenium-chromedriver,Python,Selenium,Google Chrome,Selenium Webdriver,Selenium Chromedriver,我正在使用InstaPy,它使用Python和Selenium。我根据Cron启动脚本,有时它会崩溃。所以它是非常不规则的,有时它运行良好。我已经在GitHub Repo上发布了,但是没有得到答案,所以我现在在这里问是否有人知道为什么 这是一个数字海洋ubuntu服务器,我在无头模式下使用它。驱动程序版本在日志上可见。以下是错误消息: ERROR [2018-12-10 09:53:54] [user] Error occurred while deleting cookies from we

我正在使用InstaPy,它使用Python和Selenium。我根据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[2018-12-10 09:53:54][user]从web浏览器中删除Cookie时出错!
消息:无效会话id\n(驱动程序信息:chromedriver=2.44.609551(5d576e9a44fe4c5b6a07e568f1ebc753f1214634),平台=Linux 4.15.0-42-generic x86\U 64)\n
回溯(最近一次呼叫最后一次):
文件“/root/InstaPy/InstaPy/util.py”,第1410行,智能运行
产量
文件“/my_config.py”,第43行,在
会话。跟随用户跟随者(['xxxx','xxxx','xxxx','xxxx'],数量=100,随机化=True,交互=True)
文件“/root/InstaPy/InstaPy/InstaPy.py”,第2907行,在follow\u user\u followers中
self.logfolder)
文件“/root/InstaPy/InstaPy/unfollow\u util.py”,第883行,在get\u给定用户\u followers中
通道、跳转、记录器、日志文件夹)
文件“/root/InstaPy/InstaPy/unfollow_util.py”,第722行,在“通过用户获取”对话框中
人员列表=对话框用户名提取器(按钮)
文件“/root/InstaPy/InstaPy/unfollow\u util.py”,第747行,在对话框\u用户名\u提取器中
person\u list.append(person.find\u元素通过\u xpath(“../../../*”)查找)
文件“/usr/local/lib/python3.6/dist packages/selenium/webdriver/remote/webelement.py”,第351行,按xpath查找元素
返回self.find_元素(by=by.XPATH,value=XPATH)
文件“/usr/local/lib/python3.6/dist packages/selenium/webdriver/remote/webelement.py”,第659行,在find_元素中
{“using”:by,“value”:value})[“value']
文件“/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py”,第633行,在
返回self.\u parent.execute(命令,参数)
文件“/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py”,执行中第321行
self.error\u handler.check\u响应(响应)
文件“/usr/local/lib/python3.6/dist packages/selenium/webdriver/remote/errorhandler.py”,第242行,在check_响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.WebDriverException:消息:未知错误:由于页面崩溃而删除会话
来自未知错误:无法确定加载状态
从tab崩溃
(会话信息:无头镀铬=70.0.3538.110)
(驱动程序信息:chromedriver=2.44.609551(5d576e9a44fe4c5b6a07e568f1ebc753f1214634),平台=Linux 4.15.0-42-generic x86_64)
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“/root/InstaPy/InstaPy/InstaPy.py”,第3845行,结尾
self.browser.delete_all_cookies()
文件“/usr/local/lib/python3.6/dist packages/selenium/webdriver/remote/webdriver.py”,第878行,在delete_all_cookies中
self.execute(Command.DELETE\u ALL\u COOKIES)
文件“/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py”,执行中第321行
self.error\u handler.check\u响应(响应)
文件“/usr/local/lib/python3.6/dist packages/selenium/webdriver/remote/errorhandler.py”,第242行,在check_响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.WebDriverException:消息:无法访问chrome
(会话信息:无头镀铬=71.0.3578.80)
(驱动程序信息:chromedriver=2.44.609551(5d576e9a44fe4c5b6a07e568f1ebc753f1214634),平台=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
你的代码测试会给我们一些出错的线索


解决方案 这个问题有多种解决方案。但是,根据本协议,可通过以下任一解决方案解决此问题:

  • 添加以下
    chrome\u选项

    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\u选项添加为
    ——禁用dev-shm用法。这将迫使Chrome改用
    /tmp
    目录。但这可能会降低执行速度,因为将使用磁盘而不是内存

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

从tab崩溃 从tab崩溃是Chromium团队的WIP(正在进行的工作),这与Linux试图始终将/dev/shm用于不可执行内存有关。以下是参考资料:

  • 据了解,该修复程序似乎已使用Chrome v65.0.3299.6登陆

参考文献 您可以在以下内容中找到一些相关讨论:


尽管您将错误视为:

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
你的代码测试会给我们一些出错的线索


解决方案 这个问题有多种解决方案。但是,根据本协议,可通过以下任一解决方案解决此问题:

  • 添加以下
    chrome\u选项

    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

  • 另一种方法是添加