I had the same issue after I updated to Selenium 4.0.0. The error ceased to occur after I updated my geckodriver to 0.30.0 and addressed some of the deprecated objects from previous selenium versions, but in the process I may have mistakenly imported the wrong Service and/or Options from Selenium. I think that may be what is going on in your case as well.
I could not replicate the error directly from your code. I used the code below to demonstrate the potential error and the solution.
Service object stack post:
DeprecationWarning: executable_path has been deprecated selenium python
Latest geckodriver:
https://github.com/mozilla/geckodriver/releases/tag/v0.30.0
I replicated your error by running this in Windows Subsystem for Linux (WSL2) with Ubuntu 20.04 with Selenium 4.0.0 or Selenium 4.0.0b4 (I tested both with the same outcome) with geckodriver v0.28.0.
import pathlib
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
# note the purposeful error in the service import #
from selenium.webdriver.chrome.service import Service
options = Options()
options.headless = True
# I keep my driver in my local folder with my script #
path = f"{pathlib.Path(__file__).parent.absolute()}/geckodriver"
driver = webdriver.Firefox(service=Service(path), options=options)
print(driver.capabilities['moz:geckodriverVersion'])
driver.get("https://google.com.au")
print(driver.page_source[0:97:1])
driver.quit()
This code returns:
selenium.common.exceptions.InvalidArgumentException: Message: Unrecognised option moz:debuggerAddress
This suggests to me that when running the old gecko driver selenium can't overcome the misused chrome Service. If you switch the purposefully mistaken Service import to firefox as:
from selenium.webdriver.firefox.service import Service
The code will then return:
PermissionError: [Errno 13] Permission denied: '/home/***/geckodriver'
During handling of the above exception, another exception occurred:
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable may have wrong permissions.
Finally, if you update to geckodriver v0.30.0 both of the scripts above will return:
0.30.0 #indicating gecko version #
<html itemscope="" itemtype="http://schema.org/WebPage" lang="en-CA"><head><meta charset="UTF-8"> #a subset of the HTML returned from a page source #
Taken together, I would suggest updating your geckodriver and taking a look at your imports. This is somewhat of an applied solution, if someone has a better understanding of the inner workings of the Service and Options objects they may be able to provide a more detailed answer.