{"record":{"id":"05a58d0c89c051e0","repo":"microsoft/semantic-kernel","slug":"a-client-error-occurred-while-getting-search-resul-05a58d","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/google_search.py","lineNumber":276,"sourceCode":"\n        logger.info(\n            f\"Received request for google web search with \\\n                params:\\nnum_results: {options.top}\\noffset: {options.skip}\"\n        )\n\n        full_url = f\"{CUSTOM_SEARCH_URL}{self._build_query(query, options)}\"\n        headers = {\"user_agent\": SEMANTIC_KERNEL_USER_AGENT}\n        try:\n            async with AsyncClient(timeout=5) as client:\n                response = await client.get(full_url, headers=headers)\n                response.raise_for_status()\n                return GoogleSearchResponse.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 > 10:\n            raise ServiceInvalidRequestError(\"count value must be less than or equal to 10.\")\n\n    def _parse_filter_lambda(self, filter_lambda: Callable | str) -> list[dict[str, str]]:\n        \"\"\"Parse a string lambda or string expression into a list of {field: value} dicts using AST.\"\"\"\n        expr = filter_lambda if isinstance(filter_lambda, str) else getsource(filter_lambda).strip()\n        tree = ast.parse(expr, mode=\"eval\")\n        node = tree.body\n        visitor = SearchLambdaVisitor(valid_parameters=QUERY_PARAMETERS)\n        visitor.visit(node)\n        return visitor.filters\n\n    def _build_query(self, query: str, options: SearchOptions) -> str:","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/google_search.py#L258-L294","documentation":"If httpx raises a RequestError the request never completed successfully. This covers connection failures, DNS errors, TLS problems, and timeouts; the connector uses AsyncClient(timeout=5), a hard five-second cap. The error is logged and re-raised as ServiceInvalidRequestError('A client error occurred while getting search results.').","triggerScenarios":"No network connectivity; DNS resolution failure for www.googleapis.com; ConnectTimeout/ReadTimeout because the call exceeded 5 seconds; corporate proxy or self-signed TLS interception blocking the request.","commonSituations":"Offline or sandboxed dev environment; corporate proxy not configured (HTTP_PROXY/HTTPS_PROXY); slow or flaky mobile/satellite link; Google API occasionally slow under load.","solutions":["Verify connectivity to https://www.googleapis.com from the host.","Configure proxy via HTTP_PROXY/HTTPS_PROXY env vars or a corporate trust store for TLS.","Retry transient RequestErrors with exponential backoff (the 5s timeout is hardcoded in the connector).","If timeouts are chronic, search less frequently or pre-warm results asynchronously."],"exampleFix":"# before\nresults = await google.search('skates')  # timeout/proxy -> [1304]\n\n# after\nfor attempt in range(4):\n    try:\n        results = await google.search('skates')\n        break\n    except ServiceInvalidRequestError as ex:\n        if not isinstance(ex.__cause__, RequestError):\n            raise\n        await asyncio.sleep(1.5 ** attempt)\nelse:\n    raise","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from httpx import RequestError\nfrom semantic_kernel.exceptions import ServiceInvalidRequestError\n\nfor attempt in range(4):\n    try:\n        results = await google.search(query, top=top)\n        break\n    except ServiceInvalidRequestError as ex:\n        if not isinstance(ex.__cause__, RequestError):\n            raise\n        if attempt == 3:\n            raise\n        await asyncio.sleep(1.5 ** attempt)","preventionTips":["Confirm outbound HTTPS to www.googleapis.com works from the host.","Configure HTTP_PROXY/HTTPS_PROXY in corporate networks.","Retry transient connection/timeout errors with backoff; the connector's 5s timeout is fixed."],"tags":["google-search","network","timeout","proxy"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}