From 1029e71324605be328ff9328efff5f388584924d Mon Sep 17 00:00:00 2001 From: haotian <2421912570@qq.com> Date: Tue, 9 Sep 2025 11:36:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BE=9D=E8=B5=96=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/v1/testLogin.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/api/v1/testLogin.py b/app/api/v1/testLogin.py index 11a6457..0a6fc09 100644 --- a/app/api/v1/testLogin.py +++ b/app/api/v1/testLogin.py @@ -3,7 +3,8 @@ from typing import Optional from fastapi import Depends, FastAPI, HTTPException, status from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm -from jose import JWTError, jwt +# from jose import JWTError, jwt +import jwt from passlib.context import CryptContext from pydantic import BaseModel @@ -73,9 +74,9 @@ def authenticate_user(fake_db, username: str, password: str): def create_access_token(data: dict, expires_delta: Optional[timedelta] = None): to_encode = data.copy() if expires_delta: - expire = datetime.utcnow() + expires_delta + expire = datetime.now(datetime.timezone.utc) + expires_delta else: - expire = datetime.utcnow() + timedelta(minutes=15) + expire = datetime.now(datetime.timezone.utc) + timedelta(minutes=15) to_encode.update({"exp": expire}) encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) return encoded_jwt @@ -93,7 +94,7 @@ async def get_current_user(token: str = Depends(oauth2_scheme)): if username is None: raise credentials_exception token_data = TokenData(username=username) - except JWTError: + except jwt.exceptions.PyJWTError: raise credentials_exception user = get_user(fake_users_db, username=token_data.username) if user is None: