{"record":{"id":"fe4ce91aff2c9af0","repo":"microsoft/semantic-kernel","slug":"invalid-option-name-url","errorCode":null,"errorMessage":"Invalid {option_name}: {url}","messagePattern":"Invalid (.+?): (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/openapi_plugin/server_url_validator.py","lineNumber":87,"sourceCode":") -> tuple[bool, str]:\n    \"\"\"Return whether an IP address is non-public and the category when blocked.\"\"\"\n    ip_address = ipaddress.ip_address(address)\n\n    if isinstance(ip_address, ipaddress.IPv6Address) and ip_address.ipv4_mapped:\n        ip_address = ip_address.ipv4_mapped\n\n    if isinstance(ip_address, ipaddress.IPv4Address):\n        return _try_classify_ipv4(ip_address)\n\n    return _try_classify_ipv6(ip_address)\n\n\ndef _parse_absolute_url(url: str, option_name: str = \"url\") -> ParseResult:\n    parsed_url = urlparse(url)\n    try:\n        parsed_url.port\n    except ValueError as exc:\n        raise ValueError(f\"Invalid {option_name}: {url}\") from exc\n\n    if not parsed_url.scheme or not parsed_url.netloc or not parsed_url.hostname:\n        raise ValueError(f\"Invalid {option_name}: {url}\")\n    return parsed_url\n\n\ndef _matches_allowed_base_url(url: ParseResult, allowed_base_urls: list[str]) -> bool:\n    for allowed_base_url in allowed_base_urls:\n        base_url = _parse_absolute_url(allowed_base_url, option_name=\"allowed_base_urls\")\n        if url.scheme.lower() != base_url.scheme.lower():\n            continue\n        if (url.hostname or \"\").lower() != (base_url.hostname or \"\").lower():\n            continue\n        if _effective_port(url) != _effective_port(base_url):\n            continue\n        if _matches_path_prefix(url.path, base_url.path):\n            return True\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/openapi_plugin/server_url_validator.py#L69-L105","documentation":"Thrown by _parse_absolute_url when accessing parsed_url.port raises ValueError, i.e. the URL contains an out-of-range or non-numeric port. validate_server_url re-wraps the request-URL case into FunctionExecutionException; for allowed_base_urls the ValueError propagates from model_post_init / matching.","triggerScenarios":"A URL like https://host:99999/path (port > 65535) or https://host:abc/path (non-numeric port). Appears either as the request URL or inside a configured allowed_base_urls entry.","commonSituations":"Mistyped port in config or env var; placeholder text left in a port slot; OpenAPI spec server URL with a malformed port.","solutions":["Correct the port to an integer in the range 1-65535","Omit the port to use the scheme default (443 for https, 80 for http)","Validate the URL string with urllib before passing it to the connector"],"exampleFix":"# before\nallowed = ['https://api.example.com:99999/v1']  # invalid port\n\n# after\nallowed = ['https://api.example.com:443/v1']  # or omit the port entirely","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse\n\ndef has_valid_port(url: str) -> bool:\n    p = urlparse(url)\n    if p.port is None:\n        return True  # scheme default, fine\n    return 1 <= p.port <= 65535\n\n# urlparse port access can itself raise ValueError for out-of-range ports:\ndef safe_port_ok(url: str) -> bool:\n    try:\n        _ = urlparse(url).port\n        return True\n    except ValueError:\n        return False\n\nif not safe_port_ok(url):\n    raise ValueError(f'URL {url} has an invalid port')","typeGuard":null,"tryCatchPattern":"try:\n    await validate_server_url(url, options)\nexcept FunctionExecutionException as e:\n    if 'not a valid absolute URI' in str(e) or 'Invalid' in str(e):\n        # fix the port in the url or allowed_base_urls\n        ...","preventionTips":["Validate ports are 1-65535 before storing URLs in config","Omit the port when using scheme defaults","Lint OpenAPI spec server URLs for malformed ports"],"tags":["url-validation","input-validation","config","openapi"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}