gpt4 book ai didi

python - google-chrome 无法在 flask 应用程序中以 Selenium 开头

转载 作者:行者123 更新时间:2023-12-04 18:44:43 24 4
gpt4 key购买 nike

我有一个 python 脚本,它在 flask 应用程序中与 selenium 和 Chrome 一起运行。它在我的 Mac 上运行良好。
我现在正试图在 Ubuntu 14.04 服务器上运行它,但遇到了一些问题。在应用程序外部运行时,相同的代码可以工作。但是,当它在应用程序中运行(使用相同的虚拟环境)时,Chrome 无法启动:

driver = webdriver.Chrome('/usr/bin/chromedriver',chrome_options=options,service_args=service_args, service_log_path=service_log_path)

Selenium 错误是: selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
和 Chrome 日志是:
[1549386746.673][INFO]: Launching chrome: /usr/bin/google-chrome --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-gpu --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-blink-features=ShadowDOMV0 --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --headless --ignore-certificate-errors --load-extension=/tmp/.org.chromium.Chromium.n9eYGc/internal --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.org.chromium.Chromium.9VhG53 --window-size=1920,1080 data:,
/usr/bin/google-chrome: line 8: readlink: command not found
/usr/bin/google-chrome: line 10: dirname: command not found
/usr/bin/google-chrome: line 46: exec: cat: not found
/usr/bin/google-chrome: line 45: exec: cat: not found
[1549386746.732][INFO]: [d94921c851f9c0a2faa7428e62501aca] RESPONSE InitSession ERROR unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
[1549386746.735][DEBUG]: Log type 'driver' lost 0 entries on destruction
[1549386746.735][DEBUG]: Log type 'browser' lost 0 entries on destruction

这里是 echo $PATH /home/user/folder/project/site-env/site/bin:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/bin:/bin
我非常感谢您了解为什么 chrome 找不到 readlink 等。

最佳答案

通过添加以下内容最终解决了该问题:
export PATH="$PATH:/bin:/usr/bin"到 chrome 可执行文件 (/opt/google/chrome/google-chrome)。

flask 应用程序正在另一个似乎没有路径的用户下运行。

关于python - google-chrome 无法在 flask 应用程序中以 Selenium 开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54540648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com