{"record":{"id":"e16c27bd0fafe789","repo":"xtekky/gpt4free","slug":"device-authorization-error-resp-json-get-error-e16c27","errorCode":null,"errorMessage":"Device authorization error: {resp_json.get('error')} - {resp_json.get('error_description')}","messagePattern":"Device authorization error: (.+?) - (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"g4f/Provider/qwen/qwenOAuth2.py","lineNumber":122,"sourceCode":"            \"code_challenge_method\": options[\"code_challenge_method\"],\n        }\n        async with aiohttp.ClientSession(headers={\"user-agent\": \"\"}) as session:\n            async with session.post(\n                QWEN_OAUTH_DEVICE_CODE_ENDPOINT,\n                headers={\n                    \"Content-Type\": \"application/x-www-form-urlencoded\",\n                    \"Accept\": \"application/json\",\n                    \"x-request-id\": str(uuid.uuid4()),\n                },\n                data=object_to_urlencoded(body_data),\n            ) as resp:\n                resp_json = await resp.json()\n                if resp.status != 200:\n                    raise Exception(\n                        f\"Device authorization failed {resp.status}: {resp_json}\"\n                    )\n                if not isDeviceAuthorizationSuccess(resp_json):\n                    raise Exception(\n                        f\"Device authorization error: {resp_json.get('error')} - {resp_json.get('error_description')}\"\n                    )\n                return resp_json\n\n    async def pollDeviceToken(self, options: dict) -> Union[Dict, ErrorDataDict]:\n        body_data = {\n            \"grant_type\": QWEN_OAUTH_GRANT_TYPE,\n            \"client_id\": QWEN_OAUTH_CLIENT_ID,\n            \"device_code\": options[\"device_code\"],\n            \"code_verifier\": options[\"code_verifier\"],\n        }\n        async with aiohttp.ClientSession(headers={\"user-agent\": \"\"}) as session:\n            async with session.post(\n                QWEN_OAUTH_TOKEN_ENDPOINT,\n                headers={\n                    \"Content-Type\": \"application/x-www-form-urlencoded\",\n                    \"Accept\": \"application/json\",\n                },","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/qwen/qwenOAuth2.py#L104-L140","documentation":"Raised by QwenOAuth2.startDeviceAuthorization (qwenOAuth2.py:122) when the device-authorization endpoint answers HTTP 200 but the response fails isDeviceAuthorizationSuccess() — i.e. it carries an OAuth 'error'/'error_description' pair (such as invalid_client or access_denied) instead of a device_code. A 200-with-error body means the request reached the server but was semantically rejected.","triggerScenarios":"The endpoint returns JSON like {'error': 'invalid_client', 'error_description': ...} with status 200; triggered by a wrong/revoked QWEN_OAUTH_CLIENT_ID, disallowed grant_type, or API-gateway wrappers that always return 200.","commonSituations":"Qwen rotates the public client_id embedded in g4f and old versions fail; region-specific auth endpoints rejecting the flow; responses routed through gateways that normalize status codes to 200.","solutions":["Upgrade g4f to pick up the current Qwen OAuth client constants","Log resp_json.get('error') — invalid_client points at client_id skew, access_denied at policy blocks","Retry once to rule out a transient gateway hiccup, then fall back to another provider"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = await oauth.startDeviceAuthorization(options)\nexcept Exception as exc:\n    # message embeds error/error_description from a 200 body\n    if \"invalid_client\" in str(exc):\n        raise RuntimeError(\"g4f too old for Qwen OAuth; upgrade\") from exc\n    raise","preventionTips":["Upgrade g4f when Qwen rotates OAuth constants","Never assume status 200 means success in OAuth flows — check error fields","Log the error_description verbatim for diagnosis"],"tags":["qwen","oauth","device-flow","api-contract"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}