Search code examples
pythonubuntuselenium-webdriverweb-scraping

Why does Selenium throw an "Exec format error"?


This code throws an exception:

from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get('https://www.google.com')
time.sleep(10)

Here's the backtrace:

Traceback (most recent call last):
  File "/home/orangepi/.local/lib/python3.10/site-packages/selenium/webdriver/common/selenium_manager.py", line 134, in run
    completed_proc = subprocess.run(args, capture_output=True)
  File "/usr/lib/python3.10/subprocess.py", line 503, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.10/subprocess.py", line 1863, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/home/orangepi/.local/lib/python3.10/site-packages/selenium/webdriver/common/linux/selenium-manager'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/orangepi/.local/lib/python3.10/site-packages/selenium/webdriver/common/driver_finder.py", line 38, in get_path
    path = SeleniumManager().driver_location(options) if path is None else path
  File "/home/orangepi/.local/lib/python3.10/site-packages/selenium/webdriver/common/selenium_manager.py", line 103, in driver_location
    output = self.run(args)
  File "/home/orangepi/.local/lib/python3.10/site-packages/selenium/webdriver/common/selenium_manager.py", line 140, in run
    raise WebDriverException(f"Unsuccessful command executed: {command}") from err
selenium.common.exceptions.WebDriverException: Message: Unsuccessful command executed: /home/orangepi/.local/lib/python3.10/site-packages/selenium/webdriver/common/linux/selenium-manager --browser chrome --output json


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/orangepi/Downloads/from selenium import webdriver.py", line 3, in <module>
    driver = webdriver.Chrome()
  File "/home/orangepi/.local/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/home/orangepi/.local/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 49, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
  File "/home/orangepi/.local/lib/python3.10/site-packages/selenium/webdriver/common/driver_finder.py", line 41, in get_path
    raise NoSuchDriverException(msg) from err
selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

I don't know where I am going wrong with this: chrome is installed; I tried a few tutorials and no success.


Solution

  • The error was due to me using webdriver.Chrome() which looks for webdriver for Chrome. The OS I am using runs on ARM64 and can only use Chromium. Source.

    To use Chromium, you need to use the webdriver manager.