SeleniumHQ/selenium · error · TypeError
service_args must be a sequence
Error message
service_args must be a sequence
What it means
Raised as TypeError by the FirefoxService.service_args setter when the value is a bare str or not a Sequence type. The check explicitly rejects str because a string is technically a Sequence of characters, which would be incorrectly unpacked into individual character arguments. Only list or tuple (or other non-str Sequence) of argument strings is valid.
Source
Thrown at py/selenium/webdriver/firefox/service.py:95
)
# Set a port for CDP
if "--connect-existing" not in self._service_args:
self._service_args.append("--websocket-port")
self._service_args.append(f"{utils.free_port()}")
def command_line_args(self) -> list[str]:
return ["--port", 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
- Wrap arguments in a list: service_args=['--verbose']
- Use a tuple if preferred: service_args=('--verbose',)
- Split a space-separated string with shlex.split() before passing
Example fix
// before service = Service(service_args='--verbose --marionette-port 2828') // after service = Service(service_args=['--verbose', '--marionette-port', '2828'])
Defensive patterns
Strategy: type-guard
Validate before calling
args = '--verbose'
if isinstance(args, str):
import shlex
args = shlex.split(args)
service = Service(service_args=args) Type guard
from collections.abc import Sequence
def is_arg_sequence(v) -> bool:
return not isinstance(v, str) and isinstance(v, Sequence) Try / catch
try:
service.service_args = args
except TypeError:
service.service_args = [args] if isinstance(args, str) else list(args) Prevention
- Always pass service_args as a list or tuple of strings
- Use shlex.split() to convert a string to an argument list
- Never pass a bare string to service_args
When it happens
Trigger: Passing service_args='--verbose' (a single string instead of a list), service_args=42 (an int), or service_args=None triggers the TypeError. The value must be a list/tuple of strings.
Common situations: Developers who pass a single CLI argument as a string rather than wrapping it in a list. Passing a space-separated argument string expecting it to be split.
Related errors
- service_args must be a sequence
- service_args must be a sequence
- Port needs to be an integer
- Please pass in a Boolean to this call
- Binary Location Must be a String
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/803990bbc78f30b1.
Report an issue: GitHub.