selenium.common.exceptions.InvalidSessionIdException using GeckoDriver Selenium Firefox in headless mode through Python
This error message...
selenium.common.exceptions.InvalidSessionIdException: Message:
...implies that the GeckoDriver was unable to initiate/spawn a new WebBrowsing Session i.e. Firefox Browser session.
As per the log messages geckodriver version number is no longer reflected on startup, so you must be using:
GeckoDriver version => 0.22.0 (2018-09-15)
But you are using:
- Selenium 3.141.0
- Firefox 56.0.1
So, your main issue is the incompatibility between the version of the GeckoDriver, Selenium and Firefox binaries you are using.
Solution
If you are using GeckoDriver-Selenium-Firefox combo, you need to follow the following compatibility chart for the Supported platforms: