{"record":{"id":"7814acb86d1d8a5e","repo":"xtekky/gpt4free","slug":"device-authorization-failed-resp-status-resp-j-7814ac","errorCode":null,"errorMessage":"Device authorization failed {resp.status}: {resp_json}","messagePattern":"Device authorization failed (.+?): (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"g4f/Provider/qwen/qwenOAuth2.py","lineNumber":118,"sourceCode":"        body_data = {\n            \"client_id\": QWEN_OAUTH_CLIENT_ID,\n            \"scope\": options[\"scope\"],\n            \"code_challenge\": options[\"code_challenge\"],\n            \"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,","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/qwen/qwenOAuth2.py#L100-L136","documentation":"Raised by QwenOAuth2.startDeviceAuthorization (qwenOAuth2.py:118) when the OAuth device-authorization endpoint returns any non-200 HTTP status. The body is included, so the status + JSON usually distinguishes rate limiting (429), bad client_id (400/401), or upstream outages (5xx).","triggerScenarios":"POST to QWEN_OAUTH_DEVICE_CODE_ENDPOINT returning non-200: rate-limited device flows (429), invalid client_id/grant_type in body_data, expired x-request-id handling, or Qwen auth service downtime.","commonSituations":"Starting Qwen login too frequently from one IP; g4f version carrying an outdated QWEN_OAUTH_CLIENT_ID after Qwen rotated it; transient 5xx on the Qwen identity service; corporate proxy stripping form-urlencoded bodies.","solutions":["Read the embedded status: 429 → wait and retry later; 400/401 → upgrade g4f so the bundled client_id is current","Upgrade g4f (pip install -U g4f)","Retry after a delay — transient 5xx/429 responses resolve on their own","Verify network/proxy settings allow POSTs with application/x-www-form-urlencoded bodies"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = await oauth.startDeviceAuthorization({\"scope\": \"openid\"})\nexcept Exception as exc:\n    msg = str(exc)\n    if \" 429\" in msg:\n        await asyncio.sleep(60)  # rate limited; back off and retry\n        resp = await oauth.startDeviceAuthorization({\"scope\": \"openid\"})\n    else:\n        raise","preventionTips":["Rate-limit device-login starts in your own code — one at a time","Keep g4f updated so the embedded client_id stays valid","Ensure the network path allows form-urlencoded POSTs"],"tags":["qwen","oauth","device-flow","network"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}