SeleniumHQ/selenium · error · WebDriverException
Can not connect to the Service {self._path}
Error message
Can not connect to the Service {self._path} What it means
Raised by Service.start() after the driver process is running but the service never became connectable within the retry budget (70 iterations, ~30 seconds total, sleeping up to 0.5s each). The process did not exit (otherwise error 167 fires first), it simply never answered the W3C /status endpoint on its port. On failure the service is stopped automatically before re-raising.
Source
Thrown at py/selenium/webdriver/common/service.py:120
Raises:
WebDriverException: Raised either when it can't start the service
or when it can't connect to the service
"""
if self._path is None:
raise WebDriverException("Service path cannot be None.")
self._start_process(self._path)
count = 0
try:
while True:
self.assert_process_still_running()
if self.is_connectable():
break
# sleep increasing: 0.01, 0.06, 0.11, 0.16, 0.21, 0.26, 0.31, 0.36, 0.41, 0.46, 0.5
sleep(min(0.01 + 0.05 * count, 0.5))
count += 1
if count == 70:
raise WebDriverException(f"Can not connect to the Service {self._path}")
except BaseException:
try:
self.stop()
except Exception:
logger.error("Error stopping service after a failed start.", exc_info=True)
raise
def assert_process_still_running(self) -> None:
"""Check if the underlying process is still running."""
return_code = self.process.poll()
if return_code:
raise WebDriverException(f"Service {self._path} unexpectedly exited. Status code was: {return_code}")
def is_connectable(self) -> bool:
"""Check if the service is ready via the W3C WebDriver /status endpoint.
This makes an HTTP request to the /status endpoint and verifies if it is ready to accept new sessions.
View on GitHub (pinned to aa36b38e69)
Solutions
- Increase available CPU/memory on the host or container; slow startup is the most common cause.
- Check the driver log by passing log_output to the Service to see why it is not responding.
- Verify the port is not already in use and that localhost loopback is not blocked by firewall/SELinux.
- Pin a known-good driver/browser version pair if a recent update introduced slow startup.
- Try a different port explicitly: Service(port=12345).
Example fix
# before — silent hang then failure service = Service(executable_path='/path/chromedriver') service.start() # -> Can not connect to the Service ... # after — capture logs to diagnose service = Service(executable_path='/path/chromedriver', log_output='/tmp/driver.log') service.start()
Defensive patterns
Strategy: retry
Validate before calling
null
Type guard
null
Try / catch
from selenium.common.exceptions import WebDriverException
for attempt in range(3):
try:
service = Service(executable_path=drv, log_output='/tmp/drv.log')
service.start()
break
except WebDriverException as e:
if 'Can not connect to the Service' in str(e) and attempt < 2:
continue
raise Prevention
- Pass log_output to the Service so startup failures are diagnosable.
- Provision adequate CPU/memory on CI runners to avoid slow driver startup.
- Ensure the chosen port is free and loopback is not firewalled.
When it happens
Trigger: The driver binary launched and stays alive but does not open its HTTP port in time: a very slow machine, the driver waiting on a slow DNS/proxy, a port conflict where another process holds the port, or the driver started but is blocked by a firewall from listening on localhost. The is_connectable() check probes utils.is_url_connectable on the chosen port.
Common situations: Under-provisioned CI containers, driver version that hangs on startup (e.g. chromedriver waiting for a browser that is slow to spawn), antivirus/security software intercepting localhost connections, and port exhaustion or NAT issues inside containers.
Related errors
- Service {self._path} unexpectedly exited. Status code was: {
- Service path cannot be None.
- remote server not ready in {} seconds
- SE_MANAGER_PATH does not point to a file: {env_path}
- Unsuccessful command executed: {command}
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/31e2062a7257df20.
Report an issue: GitHub.