Python WebDriverException:消息:服务 chromedriver 意外退出。状态代码是:127

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49323099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:02:56  来源:igfitidea点击:

WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127

pythongoogle-chromeseleniumselenium-webdriverselenium-chromedriver

提问by delinco

I'd like to construct my crawler using selenium on my server.

我想在我的服务器上使用 selenium 构建我的爬虫。

Thus I had installed/download required dependencies- such as chromedriver, chromium-browser etc on my Ubuntu17.10 server

因此,我在 Ubuntu17.10 服务器上安装/下载了所需的依赖项,例如 chromedriver、chromium-browser 等

However, when I run following code:

但是,当我运行以下代码时:

driver = webdriver.Chrome()

It returns following error:

它返回以下错误:

---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
<ipython-input-14-2cdab8938403> in <module>()
----> 1 driver = webdriver.Chrome()

/home/zachary/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options)
     66             service_args=service_args,
     67             log_path=service_log_path)
---> 68         self.service.start()
     69 
     70         try:

/home/zachary/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py in start(self)
     96         count = 0
     97         while True:
---> 98             self.assert_process_still_running()
     99             if self.is_connectable():
    100                 break

/home/zachary/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py in assert_process_still_running(self)
    109             raise WebDriverException(
    110                 'Service %s unexpectedly exited. Status code was: %s'
--> 111                 % (self.path, return_code)
    112             )
    113 

WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127

What does it mean that it's excited..?

它很兴奋是什么意思..?

I can't get what the original intention of that error code and where to start to fix it.

我无法理解该错误代码的初衷以及从哪里开始修复它。

It looks very rare case.

它看起来非常罕见。

Maybe relevant:

也许相关:

I had install ubuntu desktop 17.10 on my desktop but failed to get GUI boot. Thus I am just using terminal only, but it well works so far. I had installed ssh and remote controlling jupyter notebook from my mac to server desktop, and those errors comes from it. Hope this info is relevant to solve this error, otherwise will abort it.

我在桌面上安装了 ubuntu 桌面 17.10,但无法启动 GUI。因此我只使用终端,但到目前为止它运行良好。我已经从我的 mac 到服务器桌面安装了 ssh 和远程控制 jupyter notebook,这些错误来自它。希望此信息与解决此错误相关,否则将中止它。

回答by TPPZ

It seems chromedriverneeds some extra libraries. This solved the issue for me:

似乎chromedriver需要一些额外的库。这为我解决了这个问题:

apt-get install -y libglib2.0-0=2.50.3-2 \
    libnss3=2:3.26.2-1.1+deb9u1 \
    libgconf-2-4=3.2.6-4+b1 \
    libfontconfig1=2.11.0-6.7+b1

I was working on a similar setup using a docker container instead of a server/VM without X / GUI.

我正在使用 docker 容器而不是没有 X/GUI 的服务器/VM 进行类似的设置。

To figure out which dependencies are required I tried iteratively to run it from the command line like this: /opt/chromedriver/2.33/chromedriver --versionover and over again.

为了找出需要哪些依赖项,我尝试迭代地从命令行运行它,如下所示:/opt/chromedriver/2.33/chromedriver --version一遍又一遍。

Then at eache time I used commands like apt-cache search <STUFF>and apt-cache madison <STUFF>to figure out the exact version of the debpackage needed by chromedriver2.33 (in my case, but I guess something similar would work for any version of chromedriver).

然后每次我都使用类似apt-cache search <STUFF>和 的命令apt-cache madison <STUFF>来确定2.33deb所需的包的确切版本chromedriver(在我的情况下,但我想类似的东西适用于任何版本的chromedriver)。

回答by Hieu

I encountered the same error when using selenium/chromedriver on my VPS. I installed chromium-browserand the problem was gone.

我在 VPS 上使用 selenium/chromedriver 时遇到了同样的错误。我安装chromium-browser了,问题消失了。

sudo apt-get install -y chromium-browser

Maybe it's not the chromium-browseris needed, but the packages were installed along with it. However, that was a quick fix.

也许它不是chromium-browser必需的,但软件包是随它一起安装的。然而,这是一个快速解决方案。

回答by DebanjanB

While working with Selenium v3.11.0, ChromeDriver v2.36and Chrome v64.xyou have to download the latest ChromeDriverfrom the ChromeDriver - WebDriver for Chromeand place it within your system. Next while initializing the WebDriverand the WebBrowseryou have to pass the argument executable_pathalong with the absolute path of the ChromeDriveras follows :

在使用Selenium v​​3.11.0ChromeDriver v2.36Chrome v64.x 时,您必须从ChromeDriver - WebDriver for Chrome下载最新的ChromeDriver并将其放入您的系统中。接下来在初始化WebDriverWebBrowser 时,您必须传递参数以及ChromeDriver的绝对路径,如下所示:executable_path

from selenium import webdriver

driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
driver.get("http://www.python.org")

回答by Jan Havel

I had a similar issue but it turned out that my problem was incorrectly set service_log_path which was pointing to a deleted folder.

我有一个类似的问题,但事实证明我的问题是错误地设置了指向已删除文件夹的 service_log_path。

webdriver.Chrome(executable_path='/path/to/chromedriver', service_log_path='/path/to/existing/folder')

回答by TCB919

I was receiving the same selenium trace error:

我收到了相同的硒跟踪错误:

WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127

WebDriverException:消息:服务 chromedriver 意外退出。状态代码是:127

My issue was due to using a different version of chromedriver (version 78) than browser (version 79) when trying to manually run the chromedriver I would see Segmentation fault (core dumped)

我的问题是由于在尝试手动运行我会看到的 chromedriver 时使用了与浏览器(版本 79)不同版本的 chromedriver(版本 78) Segmentation fault (core dumped)

Once I updated my chromedriver to match the browser it was able to start successfully

一旦我更新了我的 chromedriver 以匹配浏览器,它就能够成功启动

Starting ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}) on port 9515

在端口 9515 上启动 ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614})

Only local connections are allowed.

只允许本地连接。

Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.

请保护 ChromeDriver 和相关测试框架使用的端口,防止恶意代码访问。

回答by python481516

Solved by carefully removing existing chromedriver and updating it to a newer version:

通过小心删除现有的 chromedriver 并将其更新到更新版本来解决:

  1. Delete all existing chromedriver files
  2. Download wget https://chromedriver.storage.googleapis.com/2.46/chromedriver_linux64.zip(replace 2.46 bit to the newer one if needed, see compatible versions here: http://chromedriver.chromium.org/downloads)
  3. Unzip, convert to executable by running chmod +x chromedriver
  4. Move it to mv -f chromedriver /usr/local/bin/chromedriverso it appears in PATH
  1. 删除所有现有的 chromedriver 文件
  2. 下载wget https://chromedriver.storage.googleapis.com/2.46/chromedriver_linux64.zip(如果需要,将 2.46 位替换为较新的,请在此处查看兼容版本:http: //chromedriver.chromium.org/downloads
  3. 解压缩,通过运行转换为可执行文件 chmod +x chromedriver
  4. 将其移至mv -f chromedriver /usr/local/bin/chromedriverPATH 中

This should solve an issue. I thought updating doesn't work because when I first tried it, I didn't remove the older version and I was still using it accidentally.

这应该解决一个问题。我认为更新不起作用,因为当我第一次尝试时,我没有删除旧版本并且我仍然不小心使用它。

回答by S7bvwqX

Reverting to older versions might also be a solution...

恢复到旧版本也可能是一个解决方案......

I am using Ubuntu 18.10 and installed the latest Selenium (3.141.0) and ChromeDriver (75.0.3770.8), but also had the same permission problems, and status code 127 afterwards.

我正在使用 Ubuntu 18.10 并安装了最新的 Selenium (3.141.0) 和 ChromeDriver (75.0.3770.8),但也遇到了相同的权限问题,之后状态代码为 127。

I tried installing Chromium and noticed that Ubuntu was using Version 73. So I reverted from the latest version of Chromedriver (75 at this time), back to Version 73 and that worked for me.

我尝试安装 Chromium 并注意到 Ubuntu 使用的是版本 73。所以我从最新版本的 Chromedriver(此时是 75)恢复到版本 73,这对我有用。

回答by Pratik Patel

I had this same issue, and the problem was due to chromedriverversion.

我遇到了同样的问题,问题出在chromedriver版本上。

Please ensure You are using latest Chrome Browseralong with latest chromedriver.

请确保您使用的是最新的Chrome 浏览器和最新的chromedriver