0
votes

I have a python script which use selenium and chromedriver. It runs on my CentOS8 VPS perfectly for 3 days without any problem.

But since this morning, the script launched, wait almost 80 secondes and display this :

[12/Jan/2021 23:04:51] ERROR - Failed : Message: chrome not reachable

Traceback (most recent call last):
  File "script.py", line 55, in <module>
    driver = launch()
  File "script.py", line 37, in launch
    browser = webdriver.Chrome('/usr/bin/chromedriver',chrome_options=chrome_options)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable

No modification have been made, why does it fail now ? I don't have any screen on my VPS so I can't see more information.

Here is some info :

yum info on chromedriver :

Nom          : chromedriver
Version      : 87.0.4280.88
Publication  : 1.el8
Architecture : x86_64
Taille       : 27 M
Source       : chromium-87.0.4280.88-1.el8.src.rpm
Dépôt        : @System
Depuis le dé : epel

google-chrome --version :

Google Chrome 87.0.4280.141 

Begin of the script :

from dotenv import load_dotenv
from logger import logger as l
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options

import time
import sys
import subprocess

load_dotenv(verbose=True)
dotenv_path = '.env'
load_dotenv(dotenv_path)

def launch():
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--no-sandbox')

    browser = webdriver.Chrome('/usr/bin/chromedriver',chrome_options=chrome_options)
    l.info('Started Chrome')
    return browser
2

2 Answers

0
votes

Problem solved but don't understand how. I just restart my VPS (reboot), and ... it works again. Weird

EDIT : Find why ! I just made a mistake at the end of my script : b.close(); But "b" don't exist, my driver variable name is "driver".

The exception was catched and not displayed, so I don't saw anything. But today, I launch a "top" command, and see all "chrome" process running in background.

Probably after several days, memory was full, and Chrome can't launch. The error was not clear but anyway, it was my fault.

-1
votes

Thumb rule

A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.


Solution

Remove the following chrome_options:

  • --no-sandbox

and execute your code as a non root user.


Outro

Here is the link to the Sandbox story.