tiangolo/fastapi · error · HTTPException
Inactive user
Error message
Inactive user
What it means
In the scopes tutorial, `get_current_active_user` (guarded by `Security(get_current_user, scopes=['me'])`) raises HTTP 400 'Inactive user' when the authenticated, scope-checked user has `disabled: True`. Sample user `alice` (`disabled: True`) triggers it once you have a token with the `me` scope.
Source
Thrown at docs_src/security/tutorial005_an_py310.py:147
raise credentials_exception
user = get_user(fake_users_db, username=token_data.username)
if user is None:
raise credentials_exception
for scope in security_scopes.scopes:
if scope not in token_data.scopes:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Not enough permissions",
headers={"WWW-Authenticate": authenticate_value},
)
return user
async def get_current_active_user(
current_user: Annotated[User, Security(get_current_user, scopes=["me"])],
):
if current_user.disabled:
raise HTTPException(status_code=400, detail="Inactive user")
return current_user
@app.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()],
) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(status_code=400, detail="Incorrect username or password")
access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
access_token = create_access_token(
data={"sub": user.username, "scope": " ".join(form_data.scopes)},
expires_delta=access_token_expires,
)
return Token(access_token=access_token, token_type="bearer")
View on GitHub (pinned to 42a41db11f)
Solutions
- Log in as an active user (`johndoe`).
- Set the user's `disabled` field to `False`.
- Tell the user the account is disabled; do not retry the same token.
Example fix
# before # me-scoped token for disabled 'alice' => 400 # after # me-scoped token for active 'johndoe' => 200
Defensive patterns
Strategy: try-catch
Validate before calling
None
Type guard
def is_inactive(resp) -> bool:
return getattr(resp, 'status_code', None) == 400 and resp.json().get('detail') == 'Inactive user' Try / catch
try:
me = client.get('/users/me/', headers=auth_header(token))
me.raise_for_status()
except httpx.HTTPStatusError as e:
if e.response.status_code == 400 and e.response.json().get('detail') == 'Inactive user':
prompt_reactivation()
raise Prevention
- Do not retry 'Inactive user' on the same token.
- When disabling a user, revoke/rotate their outstanding scoped JWTs.
- Keep the disabled flag authoritative.
When it happens
Trigger: `GET /users/me/` with a valid `me`-scoped JWT whose `sub` is a disabled user (e.g. `alice`).
Common situations: Disabled account still holding a valid scoped JWT; flag not reset after reactivation; identical pattern to the other tutorials but behind the scopes layer.
Related errors
AI-assisted analysis of tiangolo/fastapi@42a41db11f (2026-08-04).
Data as JSON: /data/errors/d3af55f814ec16a8.json.
Report an issue: GitHub.