-2

The code runs well on my laptop but when I run the same code to the VPS it shows the following errors:

        Traceback (most recent call last):
          File "vps_main.py", line 259, in <module>
            driver = webdriver.Chrome(service=s, options=chrome_options)
          File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chrome/webdriver.py", line 49, in __init__
            super().__init__(
          File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chromium/webdriver.py", line 54, in __init__
            super().__init__(
          File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 206, in __init__
            self.start_session(capabilities)
          File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 291, in start_session
            response = self.execute(Command.NEW_SESSION, caps)["value"]
          File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 346, in execute
            self.error_handler.check_response(response)
          File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
            raise exception_class(message, screen, stacktrace)
        selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
          (unknown error: DevToolsActivePort file doesn't exist)
          (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
        Stacktrace:
        #0 0x563385bab4e3 <unknown>
        #1 0x5633858dac76 <unknown>
        #2 0x563385903d78 <unknown>
        #3 0x563385900029 <unknown>
        #4 0x56338593eccc <unknown>
        #5 0x56338593e47f <unknown>
        #6 0x563385935de3 <unknown>
        #7 0x56338590b2dd <unknown>
        #8 0x56338590c34e <unknown>
        #9 0x563385b6b3e4 <unknown>
        #10 0x563385b6f3d7 <unknown>
        #11 0x563385b79b20 <unknown>
        #12 0x563385b70023 <unknown>
        #13 0x563385b3e1aa <unknown>
        #14 0x563385b946b8 <unknown>
        #15 0x563385b94847 <unknown>
        #16 0x563385ba4243 <unknown>
        #17 0x7f59ccb80609 start_thread

I tried by adding the following code but it does not solve the issue.

chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(service=s, options=chrome_options)

2 Answers2

1

You need to consider a couple of things:

Additionally you can also replace --headless with --headless=new as:

chrome_options.add_argument("--headless=new")

Note: headless property is deprecated, instead use add_argument('--headless') or add_argument('--headless=new') on Selenium 4.8.0 Python

Making the above mentioned adjustments execute your code.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I dropped both but the same issue is occurring. I checked the version of the browser in case it might be a version issue but it shows `Google Chrome 114.0.5735.198`. – Lalit mahato Jul 12 '23 at 02:53
  • I have used [chrome version 114.0.5735.90](https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip) which is the latest release. – Lalit mahato Jul 12 '23 at 02:59
  • I follow this [https://www.keeganleary.com/setting-up-chrome-and-selenium-with-python-on-a-virtual-private-server-digital-ocean/](https://www.keeganleary.com/setting-up-chrome-and-selenium-with-python-on-a-virtual-private-server-digital-ocean/) blog if in case setup issue but same issue. – Lalit mahato Jul 12 '23 at 03:02
  • @Lalitmahato Checkout the updated answer and let me know the status. – undetected Selenium Jul 12 '23 at 20:35
-1

I removed the following line of code chrome_options.add_argument("--disable-gpu") and it works for me.

chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(service=s, options=chrome_options)