selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist during autostart of LXDE
selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist during autostart of LXDE
目标:启动时自动执行python selenium 脚本。
我当前的解决方案工作了大约半年,但在 3 天前更新我的 pi 后,python 崩溃并出现此异常:selenium.common.exceptions.WebDriverException:消息:未知错误:DevToolsActivePort 文件不存在.
这是我的初始化代码:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
browser = webdriver.Chrome(chrome_options=chrome_options, service_args=["--verbose", "--log-path=/home/pi/chromedriver.log"])
browser.implicitly_wait(10)
browser.set_window_size(800, 600)
browser.get(...)
和 chromedriver returns:
[1571045268,786][INFO]: Launching chrome: /usr/bin/chromium-browser --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-dev-shm-usage --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --headless --ignore-certificate-errors --load-extension=/tmp/.org.chromium.Chromium.ka9jxU/internal --log-level=0 --metrics-recording-only --no-first-run --no-sandbox --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.org.chromium.Chromium.13RyA2 data:,
: getrandom indicates that the entropy pool has not been initialized. Rather than continue with poor entropy, this process will block until entropy is available.
[1571045328,829][INFO]: Failed to connect to Chrome. Attempting to kill it.
[1571045328,842][INFO]: [4c8ff7afd4ca8a1d7e7d0313509df6dc] RESPONSE InitSession ERROR unknown error: DevToolsActivePort file doesn't exist
[1571045328,842][DEBUG]: Log type 'driver' lost 0 entries on destruction
[1571045328,842][DEBUG]: Log type 'browser' lost 0 entries on destruction
[0100/000000.682302:ERROR:zygote_linux.cc(660)] write: Datenübergabe unterbrochen (broken pipe) (32)
我正在使用自动启动文件 ~/.config/lxsession/LXDE-pi/autostart 和这个命令:@/home/pi/script/main.py > /home/pi/script.log 2>&1 &
顺便说一句 main.py 被标记为一个可执行文件并使用 python3。
如果我通过 ssh 手动启动脚本,我没有任何问题。所以我假设它是由于在启动/自动启动过程中缺少环境变量或类似的东西导致铬崩溃引起的。如您所见,我已经尝试了 .
的答案
我当前的 chromium 版本是 Chromium 72.0.3626.121 Built on Raspbian , running on Raspbian 9.11
并且
chromedriver 版本是 ChromeDriver 72.0.3626.121
我自己找到了答案,它是由 getrandom indicates that the entropy pool has not been initialized. Rather than continue with poor entropy, this process will block until entropy is available.
引起的,这表明缺少熵源导致 chromedriver 崩溃,因为建立熵源需要很长时间。我所要做的就是安装 rng-tools 并且脚本没有崩溃。有关详细信息,请阅读此 blog post,它帮助我解决了此问题。
目标:启动时自动执行python selenium 脚本。 我当前的解决方案工作了大约半年,但在 3 天前更新我的 pi 后,python 崩溃并出现此异常:selenium.common.exceptions.WebDriverException:消息:未知错误:DevToolsActivePort 文件不存在.
这是我的初始化代码:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
browser = webdriver.Chrome(chrome_options=chrome_options, service_args=["--verbose", "--log-path=/home/pi/chromedriver.log"])
browser.implicitly_wait(10)
browser.set_window_size(800, 600)
browser.get(...)
和 chromedriver returns:
[1571045268,786][INFO]: Launching chrome: /usr/bin/chromium-browser --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-dev-shm-usage --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --headless --ignore-certificate-errors --load-extension=/tmp/.org.chromium.Chromium.ka9jxU/internal --log-level=0 --metrics-recording-only --no-first-run --no-sandbox --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.org.chromium.Chromium.13RyA2 data:,
: getrandom indicates that the entropy pool has not been initialized. Rather than continue with poor entropy, this process will block until entropy is available.
[1571045328,829][INFO]: Failed to connect to Chrome. Attempting to kill it.
[1571045328,842][INFO]: [4c8ff7afd4ca8a1d7e7d0313509df6dc] RESPONSE InitSession ERROR unknown error: DevToolsActivePort file doesn't exist
[1571045328,842][DEBUG]: Log type 'driver' lost 0 entries on destruction
[1571045328,842][DEBUG]: Log type 'browser' lost 0 entries on destruction
[0100/000000.682302:ERROR:zygote_linux.cc(660)] write: Datenübergabe unterbrochen (broken pipe) (32)
我正在使用自动启动文件 ~/.config/lxsession/LXDE-pi/autostart 和这个命令:@/home/pi/script/main.py > /home/pi/script.log 2>&1 &
顺便说一句 main.py 被标记为一个可执行文件并使用 python3。
如果我通过 ssh 手动启动脚本,我没有任何问题。所以我假设它是由于在启动/自动启动过程中缺少环境变量或类似的东西导致铬崩溃引起的。如您所见,我已经尝试了
我当前的 chromium 版本是 Chromium 72.0.3626.121 Built on Raspbian , running on Raspbian 9.11
并且
chromedriver 版本是 ChromeDriver 72.0.3626.121
我自己找到了答案,它是由 getrandom indicates that the entropy pool has not been initialized. Rather than continue with poor entropy, this process will block until entropy is available.
引起的,这表明缺少熵源导致 chromedriver 崩溃,因为建立熵源需要很长时间。我所要做的就是安装 rng-tools 并且脚本没有崩溃。有关详细信息,请阅读此 blog post,它帮助我解决了此问题。