{"record":{"id":"ee3bc648aa2f0549","repo":"microsoft/semantic-kernel","slug":"no-token-received","errorCode":null,"errorMessage":"No token received.","messagePattern":"No token received\\.","errorType":"exception","errorClass":"AgentInvokeException","httpStatus":null,"severity":"error","filePath":"python/samples/demos/copilot_studio_agent/src/direct_line_agent.py","lineNumber":75,"sourceCode":"                headers = {\"Authorization\": f\"Bearer {self.bot_secret}\"}\n                async with self.session.post(url, headers=headers) as resp:\n                    if resp.status == 200:\n                        data = await resp.json()\n                        self.directline_token = data.get(\"token\")\n                        if not self.directline_token:\n                            logger.error(\"Token generation response missing token: %s\", data)\n                            raise AgentInvokeException(\"No token received from token generation.\")\n                    else:\n                        logger.error(\"Token generation endpoint error status: %s\", resp.status)\n                        raise AgentInvokeException(\"Failed to generate token using bot_secret.\")\n            else:\n                async with self.session.get(self.token_endpoint) as resp:\n                    if resp.status == 200:\n                        data = await resp.json()\n                        self.directline_token = data.get(\"token\")\n                        if not self.directline_token:\n                            logger.error(\"Token endpoint returned no token: %s\", data)\n                            raise AgentInvokeException(\"No token received.\")\n                    else:\n                        logger.error(\"Token endpoint error status: %s\", resp.status)\n                        raise AgentInvokeException(\"Failed to fetch token from token endpoint.\")\n        except Exception as ex:\n            logger.exception(\"Exception fetching token: %s\", ex)\n            raise AgentInvokeException(\"Exception occurred while fetching token.\") from ex\n\n    @trace_agent_get_response\n    @override\n    async def get_response(\n        self,\n        history: ChatHistory,\n        arguments: dict[str, Any] | None = None,\n        **kwargs: Any,\n    ) -> ChatMessageContent:\n        \"\"\"\n        Get a response from the DirectLine Bot.\n        \"\"\"","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/samples/demos/copilot_studio_agent/src/direct_line_agent.py#L57-L93","documentation":"An AgentInvokeException from the fallback (no bot_secret) branch: GET to token_endpoint returned 200 but the JSON body lacked a 'token' field. Functionally the same malformed-response condition as the bot_secret branch, just reached via the alternate token_endpoint path.","triggerScenarios":"self.bot_secret is unset, so the agent GETs self.token_endpoint; it returns 200 with a body that does not contain 'token'.","commonSituations":"token_endpoint points at an endpoint returning a different schema; a gateway returns a health-check 200 without token data; the endpoint URL is correct but the service isn't a token issuer.","solutions":["Inspect the logged body (logger.error) to find the real token key.","Confirm token_endpoint is the actual token-issuing URL, not a generic service base URL.","Switch to the bot_secret flow if the token_endpoint path is unsupported for your setup."],"exampleFix":"// before\nself.directline_token = data.get(\"token\")  # body had different key\n\n// after\nlogger.error(\"Token endpoint body: %s\", data)\nself.directline_token = data.get(\"token\") or data.get(\"access_token\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    await fetch_token()\nexcept AgentInvokeException as e:\n    if \"No token received\" in str(e):\n        logger.error(\"Token endpoint 200 without token; inspect body schema.\")\n    raise","preventionTips":["Confirm token_endpoint returns the canonical {\"token\": ...} shape.","Prefer the bot_secret flow for deterministic auth."],"tags":["network","authentication","directline","copilot-studio","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}