From 89ebbed67b7a5d102e23ca2b61c24b320bb9003a Mon Sep 17 00:00:00 2001 From: "USIGLOBAL\\daniel_tsai" Date: Thu, 22 Aug 2024 15:12:40 +0800 Subject: [PATCH] fix: DeprecationWarning for datetime.utcnow() by using datetime.now(UTC) --- backend/utils/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/utils/utils.py b/backend/utils/utils.py index 288db1fb5..a4cce38af 100644 --- a/backend/utils/utils.py +++ b/backend/utils/utils.py @@ -6,7 +6,7 @@ from apps.webui.models.users import Users from typing import Union, Optional from constants import ERROR_MESSAGES from passlib.context import CryptContext -from datetime import datetime, timedelta +from datetime import datetime, timedelta, UTC import jwt import uuid import logging @@ -40,7 +40,7 @@ def create_token(data: dict, expires_delta: Union[timedelta, None] = None) -> st payload = data.copy() if expires_delta: - expire = datetime.utcnow() + expires_delta + expire = datetime.now(UTC) + expires_delta payload.update({"exp": expire}) encoded_jwt = jwt.encode(payload, SESSION_SECRET, algorithm=ALGORITHM)