{"record":{"id":"1efccb37e5a6ad1d","repo":"SeleniumHQ/selenium","slug":"service-args-must-be-a-sequence","errorCode":null,"errorMessage":"service_args must be a sequence","messagePattern":"service_args must be a sequence","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/chrome/service.py","lineNumber":73,"sourceCode":"            log_output=log_output,\n            env=env,\n            **kwargs,\n        )\n\n    def command_line_args(self) -> list[str]:\n        # skip when CHROME_LOG_FILE is set; --enable-chrome-logs would override the user's log file\n        args = [] if \"CHROME_LOG_FILE\" in self.env else [\"--enable-chrome-logs\"]\n        return args + [f\"--port={self.port}\"] + self._service_args\n\n    @property\n    def service_args(self) -> Sequence[str]:\n        \"\"\"Returns the sequence of service arguments.\"\"\"\n        return self._service_args\n\n    @service_args.setter\n    def service_args(self, value: Sequence[str]):\n        if isinstance(value, str) or not isinstance(value, Sequence):\n            raise TypeError(\"service_args must be a sequence\")\n        self._service_args = list(value)\n","sourceCodeStart":55,"sourceCodeEnd":75,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/chrome/service.py#L55-L75","documentation":"The `service_args` setter on `chrome.service.Service` validates its input: it explicitly rejects `str` (a common mistake since a string is technically a Sequence) and any non-Sequence type. Selenium needs a list of separate command-line flags to forward to the chromedriver process, so a single space-delimited string cannot be split reliably by the library. The check is `isinstance(value, str) or not isinstance(value, Sequence)`.","triggerScenarios":"Constructing `Service(service_args=\"--verbose --log-level=ALL\")` (passing a single string), `Service(service_args=\"--verbose\")`, `Service(service_args=42)`, or `Service(service_args={\"a\": 1})` (a dict is a Sequence of keys but used incorrectly). Setting `service.service_args = ...` after construction triggers the same setter.","commonSituations":"Copying examples from older blog posts that pass a single quoted string. Migrating from a CLI habit of one flag string. Passing a generator or iterator (not a Sequence). Passing a tuple works but is unusual.","solutions":["Pass a list of flags: `Service(service_args=[\"--verbose\", \"--log-level=ALL\"])`.","If you have one combined string, split it first: `Service(service_args=\"--verbose\".split())` or `shlex.split(flags)`.","For logging specifically, prefer setting the `CHROME_LOG_FILE` env var or `--allow-storage-access` style flags as list items."],"exampleFix":"// before\nfrom selenium.webdriver.chrome.service import Service\nsvc = Service(service_args=\"--verbose --log-level=ALL\")  # TypeError\n// after\nsvc = Service(service_args=[\"--verbose\", \"--log-level=ALL\"])","handlingStrategy":"type-guard","validationCode":"from collections.abc import Sequence\nflags = \"--verbose\"\nassert not isinstance(flags, str) and isinstance(flags, Sequence), \"pass a list of flags\"\nservice_args = list(flags)","typeGuard":"def is_valid_service_args(value) -> bool:\n    return not isinstance(value, str) and isinstance(value, __import__(\"collections.abc\").abc.Sequence)","tryCatchPattern":"from selenium.common.exceptions import ... \ntry:\n    svc = Service(service_args=flags)\nexcept TypeError:\n    svc = Service(service_args=shlex.split(flags) if isinstance(flags, str) else list(flags))","preventionTips":["Always pass a list of flags, never a single string.","Use shlex.split() to convert a shell-style flag string into a list.","Annotate config with list[str] so type checkers catch the mistake."],"tags":["service-args","type-check","chromedriver","python"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}