tiangolo/fastapi · error · HTTPException
Inactive user
Error message
Inactive user
What it means
Default-parameter twin of error 55: `get_current_active_user` (`Security(get_current_user, scopes=['me'])`) raises HTTP 400 'Inactive user' when the resolved, scope-checked user has `disabled: True`. Sample user `alice` triggers it.
Source
Thrown at docs_src/security/tutorial005_py310.py:146
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: 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: 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
- Authenticate as an active user (`johndoe`).
- Set the user's `disabled` field to `False`.
- Show a disabled-account message; do not retry.
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.
- Revoke scoped JWTs when disabling a user.
- Keep the disabled flag in sync with admin tooling.
When it happens
Trigger: `GET /users/me/` with a valid `me`-scoped JWT whose user is disabled.
Common situations: Disabled account with valid outstanding scoped JWT; flag not reset on reactivation.
Related errors
AI-assisted analysis of tiangolo/fastapi@42a41db11f (2026-08-04).
Data as JSON: /data/errors/6d7b7787a50a5021.json.
Report an issue: GitHub.