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

ID : 131388

viewed : 6

Tags : pythongoogle-chromeseleniumselenium-webdriverselenium-chromedriverpython

Top 5 Answer for python - WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127

vote vote

91

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

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.

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

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 deb package needed by chromedriver 2.33 (in my case, but I guess something similar would work for any version of chromedriver).

Edit

As suggested in the comments, using the ldd command to print shared object dependencies may be another option. As of today my chromedriver version after a few years from the original answer is 83.0.4103.14 - the dependencies are different as well, but see below to get an idea of what could be missing:

$ /usr/local/bin/chromedriver --version ChromeDriver 83.0.4103.14 (be04594a2b8411758b860104bc0a1033417178be-refs/branch-heads/4103@{#119}) $ ldd /usr/local/bin/chromedriver         linux-vdso.so.1 (0x00007fffff7f0000)         libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f414739d000)         libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f414737a000)         librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f414736f000)         libglib-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f4147246000)         libnss3.so => /usr/lib/x86_64-linux-gnu/libnss3.so (0x00007f41470f7000)         libnssutil3.so => /usr/lib/x86_64-linux-gnu/libnssutil3.so (0x00007f41470c4000)         libnspr4.so => /usr/lib/x86_64-linux-gnu/libnspr4.so (0x00007f4147082000)         libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f4146f45000)         libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4146df6000)         libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4146ddb000)         libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4146be9000)         /lib64/ld-linux-x86-64.so.2 (0x00007f4147e56000)         libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f4146b76000)         libplc4.so => /usr/lib/x86_64-linux-gnu/libplc4.so (0x00007f4146b6d000)         libplds4.so => /usr/lib/x86_64-linux-gnu/libplds4.so (0x00007f4146b68000)         libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f4146b3e000)         libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f4146b38000)         libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f4146b30000)         libbsd.so.0 => /usr/lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f4146b14000) 

From man ldd:

ldd prints the shared objects (shared libraries) required by each program or shared object specified on the command line.

...

In the usual case, ldd invokes the standard dynamic linker (see ld.so(8)) with the LD_TRACE_LOADED_OBJECTS environment variable set to 1. This causes the dynamic linker to inspect the program's dynamic dependencies, and find (according to the rules described in ld.so(8)) and load the objects that satisfy those dependencies. For each dependency, ldd displays the location of the matching object and the (hexadecimal) address at which it is loaded.

vote vote

83

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

sudo apt-get install -y chromium-browser 

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

vote vote

78

Run this command to troubleshoot: ./chromedriver (where your chrome driver binary is).

You might see an error like this:

./chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

To solve this error, simply run: sudo apt-get install libnss3.

Then check again and see if it works this time: ./chromedriver.

Some other packages might be missing as well. Here is an exhaustive list:

gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

You probably don't need all of them but the ones you need are likely to be listed above.

vote vote

69

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.

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

59

While working with Selenium v3.11.0, ChromeDriver v2.36 and Chrome v64.x you have to download the latest ChromeDriver from the ChromeDriver - WebDriver for Chrome and place it within your system. Next while initializing the WebDriver and the WebBrowser you have to pass the argument executable_path along with the absolute path of the ChromeDriver as follows :

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

Top 3 video Explaining python - WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 127

Related QUESTION?