The script runs on the local machine on Python, on linux VDS refuses to see chromedriver .

xvfb installed, selenium installed, Python2.7 is installed, the path to the chrome driver is specified.

The code is:

 from selenium import webdriver driver = webdriver.Chrome('/home/selenium/Drivers/chromedriver') driver.get('https://google.com') ff = open("file.txt", "w") ff.write(driver.page_source.encode("utf-8")) ff.close() driver.close() 

Before sending, I change the line from the path to the chrome driver as on the server:

 from selenium import webdriver #driver = webdriver.Chrome('/home/Selenium/Drivers/chromedriver') driver = webdriver.Chrome('/home/chromedriver') driver.get('https://google.com') ff = open("file.txt", "w") ff.write(driver.page_source.encode("utf-8")) ff.close() driver.close() 

I send it to the server. Chromedriver is really on the path indicated by me:

 root@70678:/home# ls chromedriver 

I run the script and get:

  File "start.py", line 6, in <module> driver = webdriver.Chrome('/home/chromedriver') File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__ self.service.start() File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 96, in start self.assert_process_still_running() File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running % (self.path, return_code) selenium.common.exceptions.WebDriverException: Message: Service /home/chromedriver unexpectedly exited. Status code was: 127 

Please tell me what it means, and what could be the reason?

  • one
    Run by hand the same command that is executed from the script. No errors? If not, then look at the environment variable and access rights, if there is, then sort it out in the course of finding out the reasons. - 0andriy

1 answer 1

Thank you so much for the hint. In the process of debugging, the gradual work with the python in the terminal helped a lot. As a result, my code has changed and it really works on VDS running on ubuntu 16 ...:

 from selenium import webdriver from xvfbwrapper import Xvfb vdisplay = Xvfb() vdisplay.start() from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-setuid-sandbox") driver = webdriver.Chrome('/home/chromedriver', chrome_options=chrome_options) driver.get('https://google.com') ff = open("file.txt", "w") ff.write(driver.page_source.encode("utf-8")) ff.close() driver.close() vdisplay.stop() 

Very helpful code from the comment: https://stackoverflow.com/a/31700657/7803940

For all sufferers, I am writing a memo for setting up selenium + chromedriver when working in python on vds (Virtual Server):

  1. Install chrome on VDS | necessarily the presence of the browser in the system
  2. Install pip on vds | helps to easily install add. python packages
  3. Download chromedriver | Do not forget to download cromedriver
  4. Install selenium | Selenium in python is installed using pip
  5. Install a virtual screen linux Xvfb | put in apt-get terminal ... etc
  6. Set xvfbwrapper to python | pip install xvfbwrapper
  • Another help is installing an interactive python ipython , for example. - 0andriy