{"record":{"id":"19c6607c127adb5f","repo":"SeleniumHQ/selenium","slug":"port-number-must-be-in-the-range-1-65535","errorCode":null,"errorMessage":"Port number must be in the range 1..65535","messagePattern":"Port number must be in the range 1\\.\\.65535","errorType":"exception","errorClass":"WebDriverException","httpStatus":null,"severity":"warning","filePath":"py/selenium/webdriver/firefox/firefox_profile.py","lineNumber":117,"sourceCode":"        \"\"\"Gets the profile directory that is currently being used.\"\"\"\n        return self._profile_dir\n\n    @property\n    @deprecated(\"The port is stored in the Service class\")\n    def port(self):\n        \"\"\"Gets the port that WebDriver is working on.\"\"\"\n        return self._port\n\n    @port.setter\n    @deprecated(\"The port is stored in the Service class\")\n    def port(self, port) -> None:\n        \"\"\"Sets the port that WebDriver will be running on.\"\"\"\n        if not isinstance(port, int):\n            raise WebDriverException(\"Port needs to be an integer\")\n        try:\n            port = int(port)\n            if port < 1 or port > 65535:\n                raise WebDriverException(\"Port number must be in the range 1..65535\")\n        except (ValueError, TypeError):\n            raise WebDriverException(\"Port needs to be an integer\")\n        self._port = port\n        self.set_preference(\"webdriver_firefox_port\", self._port)\n\n    @property\n    @deprecated(\"Allowing untrusted certs is toggled in the Options class\")\n    def accept_untrusted_certs(self):\n        return self._desired_preferences[\"webdriver_accept_untrusted_certs\"]\n\n    @accept_untrusted_certs.setter\n    @deprecated(\"Allowing untrusted certs is toggled in the Options class\")\n    def accept_untrusted_certs(self, value) -> None:\n        if not isinstance(value, bool):\n            raise WebDriverException(\"Please pass in a Boolean to this call\")\n        self.set_preference(\"webdriver_accept_untrusted_certs\", value)\n\n    @property","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/firefox/firefox_profile.py#L99-L135","documentation":"Raised by the (deprecated) FirefoxProfile.port setter when the int port value falls outside the valid TCP range 1..65535. It fires only after the isinstance(port, int) check passes and int(port) succeeds, so the value is a valid integer but numerically out of range (0, negative, or > 65535).","triggerScenarios":"Assigning profile.port = 0, profile.port = -1, or profile.port = 70000. Also a bool True (which is int 1) passes range, but False (int 0) fails it.","commonSituations":"Using port 0 expecting 'OS chooses' (the profile setter does not support that semantics, unlike the Service), passing an out-of-range value from misparsed config, or copying a port number with a typo.","solutions":["Set the port on the Firefox Service, which supports 0 for OS-assigned: Service(port=0).","If using the deprecated profile.port, supply a value strictly within 1..65535.","Validate the value before assignment if it comes from external config."],"exampleFix":"# before (deprecated, out of range)\nprofile.port = 0  # -> WebDriverException: Port number must be in the range 1..65535\n\n# after — let the Service handle port allocation\nfrom selenium.webdriver.firefox.service import Service\nservice = Service(port=0)  # OS picks a free port\ndriver = webdriver.Firefox(service=service)","handlingStrategy":"validation","validationCode":"assert isinstance(port, int) and 1 <= port <= 65535, 'port must be in 1..65535'\nprofile.port = port","typeGuard":"def is_valid_port(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 65535","tryCatchPattern":"from selenium.common.exceptions import WebDriverException\ntry:\n    profile.port = raw\nexcept WebDriverException:\n    raw = max(1, min(65535, int(raw)))\n    profile.port = raw","preventionTips":["Use the Firefox Service for port configuration, which supports 0 for OS-assigned.","Validate port range at config-load time.","Reject 0/negative/oversized values in your config schema."],"tags":["firefox","profile","deprecated","validation","port-range"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}