SeleniumHQ/selenium · error · TypeError

service_args must be a sequence

Error message

service_args must be a sequence

What it means

Raised by the EdgeService.service_args setter when the assigned value is a str or is not a collections.abc.Sequence. Strings are explicitly excluded even though str is technically a Sequence (to prevent a single '--flag' being split into characters). The setter requires an actual sequence of strings like a list or tuple.

Source

Thrown at py/selenium/webdriver/edge/service.py:81

        return args + [f"--port={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]):
        """Sets the service arguments for the Edge driver.

        Args:
            value: A sequence of strings representing service arguments.

        Raises:
            TypeError: If value is not a sequence or is a string.
        """
        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

  1. Pass flags as a list: service.service_args = ['--verbose', '--whitelisted-ips='].
  2. If you have a space-separated string, split it first: service.service_args = s.split().
  3. Prefer setting service_args at construction time via the constructor parameter.

Example fix

# before
service.service_args = '--verbose --port=9515'  # -> TypeError

# after
service.service_args = ['--verbose', '--whitelisted-ips=']
Defensive patterns

Strategy: type-guard

Validate before calling

from collections.abc import Sequence
def normalize_service_args(v):
    if isinstance(v, str) or not isinstance(v, Sequence):
        raise TypeError('service_args must be a non-string sequence')
    return list(v)

Type guard

def is_valid_service_args(v) -> bool:
    from collections.abc import Sequence
    return not isinstance(v, str) and isinstance(v, Sequence)

Try / catch

try:
    service.service_args = raw
except TypeError:
    service.service_args = raw.split() if isinstance(raw, str) else list(raw)

Prevention

When it happens

Trigger: Assigning service.service_args = '--verbose' (a single string), service.service_args = 123, or passing service_args as a string to the Edge Service constructor path that routes through this setter. Note the constructor itself coerces via list(service_args or []) and would NOT trigger this, so the setter is the specific trigger.

Common situations: Porting code that used a single space-separated string for flags, or a config system that yields strings instead of lists. Assigning after construction rather than at construction time is the typical trigger.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/e8b967ae81e02350. Report an issue: GitHub.