エラーの対処法 chrome not reachable
VPSなどの仮想環境でseleniumを扱っていると、こんなエラーに遭遇しました。
selenium.common.exceptions.WebDriverException: Message: chrome not reachable (Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 4.4.0-57-generic x86_64)
エラーメッセージを直訳すると、「クロームは到達しなかった」的な。
原因
chromeのプロセスが溢れかえっている。
GUIで言うところの、chromeのブラウザを開きすぎて星の数ほどのタブがある状態。(たぶん)
chromeのプロセスが溢れかえっているか確かめてみよう。
ps aux | grep chrome
このコマンドで、私は溢れんばかりのchromeプロセスがでてきた
対処法
chromedriverのコマンドで動いているプロセスを全部killします。
killでPIDを一つ一つ打てる数ではないので、killallを使います。
killall chrome killall chromedriver killall chrome-sandbox
対処法2
解決法として以下のseleniumのオプションを追加します。
chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-setuid-sandbox") self.driver = webdriver.Chrome("/home/uTakahiro/py3/fund/chromedriver", chrome_options=chrome_options)
まとめ
以上、終わり!