{"record":{"id":"f40086187d759415","repo":"SeleniumHQ/selenium","slug":"class-name-init-got-an-invalid-por","errorCode":null,"errorMessage":"{__class__.__name__}.__init__() got an invalid port: '{port}'","messagePattern":"(.+?)\\.__init__\\(\\) got an invalid port: '(.+?)'","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/remote/server.py","lineNumber":112,"sourceCode":"    def path(self):\n        return self._path\n\n    @path.setter\n    def path(self, path):\n        if path and not os.path.exists(path):\n            raise OSError(f\"Can't find server .jar located at {path}\")\n        self._path = path\n\n    @property\n    def port(self):\n        return self._port\n\n    @port.setter\n    def port(self, port):\n        try:\n            port = int(port)\n        except ValueError:\n            raise TypeError(f\"{__class__.__name__}.__init__() got an invalid port: '{port}'\")\n        if not (0 <= port <= 65535):\n            raise ValueError(\"port must be 0-65535\")\n        self._port = port\n\n    @property\n    def version(self):\n        return self._version\n\n    @version.setter\n    def version(self, version):\n        if version:\n            if not re.match(r\"^\\d+\\.\\d+\\.\\d+$\", str(version)):\n                raise TypeError(f\"{__class__.__name__}.__init__() got an invalid version: '{version}'\")\n        self._version = version\n\n    @property\n    def log_level(self):\n        return self._log_level","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/remote/server.py#L94-L130","documentation":"Raised as TypeError by the Server.port setter when int(port) raises ValueError — i.e., the port value cannot be converted to an integer. This catches non-numeric strings and other unconvertible types before they reach the range check. Note: the original ValueError from int() is caught and re-raised as TypeError.","triggerScenarios":"Calling Server(port='abc'), Server(port='4444a'), or Server(port=None) (if None reaches the setter) triggers the TypeError. Any value that int() cannot parse will fail here.","commonSituations":"Port values read from environment variables or config files as strings that are not numeric. Typos in port configuration. Accidentally passing a hostname:port string instead of just the port number.","solutions":["Ensure the port is an integer or a numeric string: Server(port=4444) or Server(port='4444')","Validate env-sourced ports: port = int(os.environ.get('SELENIUM_PORT', '4444'))","Strip any non-numeric characters from the port string before passing"],"exampleFix":"// before\nserver = Server(port=os.environ.get('PORT', 'abc'))\n\n// after\nport_str = os.environ.get('PORT', '4444')\nserver = Server(port=int(port_str))","handlingStrategy":"validation","validationCode":"port_str = os.environ.get('PORT', '4444')\nport = int(port_str)  # raises ValueError here if non-numeric, before reaching Server\nserver = Server(port=port)","typeGuard":"def is_intable(v) -> bool:\n    try:\n        int(v)\n        return True\n    except (ValueError, TypeError):\n        return False","tryCatchPattern":"try:\n    server = Server(port=port_value)\nexcept TypeError:\n    server = Server(port=4444)  # fallback to default","preventionTips":["Convert port config values to int explicitly before passing","Validate env-sourced port strings are numeric","Strip non-numeric characters from port configuration"],"tags":["remote","server","port","type-validation","type-error"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}