xtekky/gpt4free · error · Exception
Device authorization failed {resp.status}: {resp_json}
Error message
Device authorization failed {resp.status}: {resp_json} What it means
A bare Exception raised by GithubOAuth2Client device authorization when POSTing to the GitHub device-code endpoint (GITHUB_DEVICE_CODE_ENDPOINT) returns a non-200 status. The status and parsed JSON body are included, so common causes (401 bad client_id, 429 rate limit, 5xx) are visible in the message. This is the first step of the device flow: obtaining device_code and user_code.
Source
Thrown at g4f/Provider/github/githubOAuth2.py:105
"""
body_data = {
"client_id": self.client_id,
"scope": options.get("scope", GITHUB_COPILOT_SCOPE),
}
async with aiohttp.ClientSession() as session:
async with session.post(
GITHUB_DEVICE_CODE_ENDPOINT,
headers={
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
},
data=object_to_urlencoded(body_data),
) as resp:
resp_json = await resp.json()
if resp.status != 200:
raise Exception(
f"Device authorization failed {resp.status}: {resp_json}"
)
if not isDeviceAuthorizationSuccess(resp_json):
raise Exception(
f"Device authorization error: {resp_json.get('error')} - {resp_json.get('error_description')}"
)
return resp_json
async def pollDeviceToken(self, options: dict) -> Union[Dict, ErrorDataDict]:
"""
Poll for device token from GitHub.
Args:
options: dict with device_code
Returns:View on GitHub (pinned to 973504e177)
Solutions
- Read the embedded resp_json error field — 'incorrect_client_credentials' means the bundled client_id is wrong; update g4f
- Wait and retry for 429/5xx (device-flow rate limits reset within minutes)
- If using a custom OAuth app, verify its client_id and that the device flow is enabled for it
Defensive patterns
Strategy: retry
Try / catch
try:
device_auth = await client.authorizeDevice()
except Exception as e:
if ' 429 ' in str(e) or ' 5' in str(e):
await asyncio.sleep(30)
device_auth = await client.authorizeDevice()
raise Prevention
- Do not start the device flow in a tight loop — GitHub rate-limits device authorization
- Keep g4f's bundled client_id intact; custom apps must enable the device grant
- Check GitHub's status page during suspected outages before debugging code
When it happens
Trigger: Starting device-code login when the OAuth client_id is invalid/revoked (401), device-flow rate limits are hit (429), or GitHub is erroring (5xx).
Common situations: A fork/modified g4f with a wrong client_id; too many login attempts in a short window; GitHub OAuth outage.
Related errors
- Device authorization error: {resp_json.get('error')} - {resp
- Device code expired. Please try again.
- Authorization was denied by the user.
- device_code is required for polling
- Device authorization failed {resp.status}: {resp_json}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/31e9452d31938cc3.
Report an issue: GitHub.