SeleniumHQ/selenium · error · TypeError
service_args must be a sequence
Error message
service_args must be a sequence
What it means
Raised by the service_args setter on webkitgtk.Service when the assigned value is a str or is not a collections.abc.Sequence. Strings are explicitly rejected (even though str is technically a Sequence) to prevent accidentally passing a single argument string like '--verbose' when a list of individual argument strings is expected. The constructor accepts None or a Sequence and stores it as a list.
Source
Thrown at py/selenium/webdriver/webkitgtk/service.py:69
executable_path=executable_path,
port=port,
log_output=log_output,
env=env,
**kwargs,
)
def command_line_args(self) -> list[str]:
return ["-p", f"{self.port}"] + self._service_args
@property
def service_args(self) -> Sequence[str]:
"""Returns the sequence of service arguments."""
return self._service_args
@service_args.setter
def service_args(self, value: Sequence[str]):
if isinstance(value, str) or not isinstance(value, Sequence):
raise TypeError("service_args must be a sequence")
self._service_args = list(value)
View on GitHub (pinned to aa36b38e69)
Solutions
- Pass a list or tuple of argument strings: service.service_args = ['--debug', '--port=1234'].
- If reading from a config string, split it first: args = config_str.split() or shlex.split(config_str).
- Pass service_args in the Service constructor instead of the setter, with the same list type.
Example fix
// before service = Service() service.service_args = '--debug --verbose' // after service = Service() service.service_args = ['--debug', '--verbose']
Defensive patterns
Strategy: type-guard
Validate before calling
from collections.abc import Sequence
if isinstance(value, str) or not isinstance(value, Sequence):
raise TypeError('service_args must be a sequence of strings')
service.service_args = list(value) Type guard
from collections.abc import Sequence
def is_valid_service_args(value) -> bool:
return not isinstance(value, str) and isinstance(value, Sequence) and all(isinstance(a, str) for a in value) Try / catch
null
Prevention
- Always pass service_args as a list of strings: ['--flag', '--opt=value'].
- If reading args from a config string, split it first with shlex.split().
- Use type hints (Sequence[str]) on your own code to catch mismatches early.
When it happens
Trigger: Assigning service.service_args = '--debug' (a bare string) instead of ['--debug'] (a list); assigning an int, dict, or other non-sequence type; or assigning a single string argument where the API expects a list of separate flags.
Common situations: Configuring WebKitWebDriver with extra command-line arguments; migrating from a config format that stored args as a space-delimited string; copy-pasting CLI examples that show a string rather than a list; passing kwargs from a dictionary where the type was not validated upstream.
Related errors
- service_args must be a sequence
- module {__name__!r} has no attribute {name!r}
- Binary Location Must be a String
- service_args must be a sequence
- service_args must be a sequence
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/70386aba9a640c05.
Report an issue: GitHub.