{"record":{"id":"9820c6fd36098f6f","repo":"xtekky/gpt4free","slug":"no-valid-access-token-obtained","errorCode":null,"errorMessage":"No valid access token obtained.","messagePattern":"No valid access token obtained\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"g4f/Provider/qwen/qwenContentGenerator.py","lineNumber":36,"sourceCode":"\n    def get_current_endpoint(self, resource_url: Optional[str]) -> str:\n        url = resource_url if resource_url else self.base_url\n        if not url.startswith(\"http\"):\n            url = \"https://\" + url\n        if not url.endswith(\"/v1\"):\n            url = url.rstrip(\"/\") + \"/v1\"\n        return url\n\n    async def get_valid_token(self) -> Dict[str, str]:\n        \"\"\"\n        Obtain a valid token and endpoint from shared token manager.\n        \"\"\"\n        credentials = await self.shared_manager.getValidCredentials(self.qwen_client)\n        token = credentials.get(\"access_token\")\n        resource_url = credentials.get(\"resource_url\")\n        endpoint = self.get_current_endpoint(resource_url)\n        if not token:\n            raise Exception(\"No valid access token obtained.\")\n        return {\"token\": token, \"endpoint\": endpoint}\n","sourceCodeStart":18,"sourceCodeEnd":38,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/qwen/qwenContentGenerator.py#L18-L38","documentation":"Raised by QwenContentGenerator.get_valid_token (qwenContentGenerator.py:36) when the shared token manager returned a credentials dict whose 'access_token' key is missing or empty. It means the Qwen OAuth credential store exists but is incomplete — typically because the device-code login never finished or the stored credentials were reset after a failed refresh.","triggerScenarios":"Calling any Qwen generation path that first awaits get_valid_token(); shared_manager.getValidCredentials(...) returns a dict without a truthy 'access_token' — e.g. empty credentials loaded from disk, or a refresh cycle that returned no token.","commonSituations":"First run before completing Qwen device authorization; credentials file partially written or hand-edited; refresh token expired and was wiped (see qwenOAuth2.py:177) leaving no access token; multiple processes racing on the credentials file.","solutions":["Complete the Qwen OAuth device-code login so valid credentials are written to the token store","Delete the stale credentials file and re-authenticate from scratch","Check for TokenManagerError logs just before this — the root cause is usually a failed refresh (REFRESH_FAILED / expired refresh token)","Ensure no other process holds the lock file while credentials are being refreshed"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"async def has_valid_qwen_access(manager, client) -> bool:\n    creds = await manager.getValidCredentials(client)\n    return bool(creds.get(\"access_token\"))","typeGuard":"def has_access_token(creds: dict) -> bool:\n    return isinstance(creds, dict) and isinstance(creds.get(\"access_token\"), str) and len(creds[\"access_token\"]) > 0","tryCatchPattern":"try:\n    auth = await generator.get_valid_token()\nexcept Exception as exc:\n    if \"No valid access token\" in str(exc):\n        await run_qwen_device_login()  # re-authenticate\n    else:\n        raise","preventionTips":["Complete device authorization before enabling the Qwen provider","Monitor refresh failures — they usually precede a missing access token","Persist the credentials directory across container restarts"],"tags":["qwen","oauth","authentication","credentials"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}