{"record":{"id":"714caecc4244a083","repo":"microsoft/semantic-kernel","slug":"a-client-error-occurred-while-getting-search-resul","errorCode":null,"errorMessage":"A client error occurred while getting search results.","messagePattern":"A client error occurred while getting search results\\.","errorType":"exception","errorClass":"ServiceInvalidRequestError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/brave.py","lineNumber":238,"sourceCode":"        params = self._build_request_parameters(query, options)\n\n        logger.info(f\"Sending GET request to {url}\")\n\n        headers = {\n            \"X-Subscription-Token\": self.settings.api_key.get_secret_value(),\n            \"user_agent\": SEMANTIC_KERNEL_USER_AGENT,\n        }\n        try:\n            async with AsyncClient(timeout=5) as client:\n                response = await client.get(url, headers=headers, params=params)\n                response.raise_for_status()\n                return BraveSearchResponse.model_validate_json(response.text)\n        except HTTPStatusError as ex:\n            logger.error(f\"Failed to get search results: {ex}\")\n            raise ServiceInvalidRequestError(\"Failed to get search results.\") from ex\n        except RequestError as ex:\n            logger.error(f\"Client error occurred: {ex}\")\n            raise ServiceInvalidRequestError(\"A client error occurred while getting search results.\") from ex\n        except Exception as ex:\n            logger.error(f\"An unexpected error occurred: {ex}\")\n            raise ServiceInvalidRequestError(\"An unexpected error occurred while getting search results.\") from ex\n\n    def _validate_options(self, options: SearchOptions) -> None:\n        if options.top <= 0:\n            raise ServiceInvalidRequestError(\"count value must be greater than 0.\")\n        if options.top >= 21:\n            raise ServiceInvalidRequestError(\"count value must be less than 21.\")\n\n        if options.skip < 0:\n            raise ServiceInvalidRequestError(\"offset must be greater than or equal to 0.\")\n        if options.skip > 9:\n            raise ServiceInvalidRequestError(\"offset must be less than 10.\")\n\n    def _get_url(self) -> str:\n        return DEFAULT_URL\n","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/brave.py#L220-L256","documentation":"Raised when httpx raises a RequestError — a client-side/network error before a response is received (connection failure, DNS resolution error, timeout, TLS error). The connector wraps it as ServiceInvalidRequestError. Unlike the HTTP-status error, this means the request never successfully reached or returned from Brave.","triggerScenarios":"The async GET to the Brave URL fails at the transport layer: no network connectivity, DNS failure for the Brave host, the 5-second timeout (AsyncClient(timeout=5)) expires, or a proxy/TLS configuration problem.","commonSituations":"Running in an environment without outbound internet, behind a restrictive proxy/firewall, DNS misconfiguration, or the Brave endpoint being slow enough to exceed the 5s timeout.","solutions":["Verify outbound network connectivity and DNS resolution for the Brave API host from the runtime environment.","Increase resilience with a retry/backoff wrapper for transient RequestErrors, and check whether a proxy is required.","If timeouts recur, investigate latency or raise the client timeout (requires subclassing/overriding, since 5s is hardcoded)."],"exampleFix":"// before\nresults = await connector.search(query)\n// after\nfor attempt in range(3):\n    try:\n        results = await connector.search(query)\n        break\n    except ServiceInvalidRequestError as e:\n        if not isinstance(e.__cause__, RequestError):\n            raise\n        await asyncio.sleep(2 ** attempt)\n","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceInvalidRequestError\nfrom httpx import RequestError\n\nfor attempt in range(3):\n    try:\n        results = await connector.search(query)\n        break\n    except ServiceInvalidRequestError as e:\n        if isinstance(e.__cause__, RequestError):\n            import asyncio\n            await asyncio.sleep(2 ** attempt)\n            continue\n        raise","preventionTips":["Ensure outbound network/DNS access to the Brave host from the runtime.","Configure a proxy if required by the environment.","Add retry/backoff for transient RequestError and timeouts."],"tags":["brave","network","timeout","http"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}