xtekky/gpt4free · error · Exception

Device authorization error: {resp_json.get('error')} - {resp

Error message

Device authorization error: {resp_json.get('error')} - {resp_json.get('error_description')}

What it means

A bare Exception raised after a 200 response from the device authorization endpoint when the payload fails the isDeviceAuthorizationSuccess check — i.e. it carries an OAuth error object instead of a device_code. The message embeds the standard OAuth error and error_description fields (e.g. authorization_pending, slow_down, expired_token are handled separately upstream; others land here).

Source

Thrown at g4f/Provider/github/githubOAuth2.py:110

        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:
            dict with access_token, token_type, scope or status=pending
        """
        body_data = {
            "grant_type": "urn:ietf:params:oauth:grant-type:device_code",
            "client_id": self.client_id,

View on GitHub (pinned to 973504e177)

Solutions

  1. Read the embedded error_description — it states the exact OAuth failure reason
  2. For unsupported_grant_type / disabled device flow, switch to a client_id that enables the device authorization grant or update g4f
  3. Retry after correcting the OAuth app configuration; transient policy errors clear with a new request
Defensive patterns

Strategy: try-catch

Try / catch

try:
    device_auth = await client.authorizeDevice()
except Exception as e:
    if 'Device authorization error' in str(e):
        # inspect embedded error_description; fix OAuth app config, then retry once
        log.warning('device auth rejected: %s', e)

Prevention

When it happens

Trigger: HTTP 200 from GITHUB_DEVICE_CODE_ENDPOINT whose body contains error/error_description, such as 'unsupported_grant_type' when the OAuth app does not allow the device flow, or malformed policy rejections.

Common situations: Custom OAuth app without device-flow enabled; GitHub policy changes adding new error codes the client does not special-case.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/aa81ae78afd1eb69. Report an issue: GitHub.