From 8a2d8a3abf4b4dcecae5fdfbc4560e2903107094 Mon Sep 17 00:00:00 2001 From: CI Bot Date: Fri, 24 Jul 2026 01:13:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=9B=BF=E6=8D=A2=E5=BA=9F?= =?UTF-8?q?=E5=BC=83=E7=9A=84datetime.utcnow()=E4=B8=BAdatetime.now(timezo?= =?UTF-8?q?ne.utc)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Python 3.12+ 中 datetime.utcnow() 已废弃 - 替换为推荐写法 datetime.now(timezone.utc) - 涉及 jwt_service.py 和 health.py 共4处 - 2个文件,+6/-6 --- apps/api/app/api/routes/health.py | 6 +++--- packages/application/auth/jwt_service.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) mode change 100755 => 100644 packages/application/auth/jwt_service.py diff --git a/apps/api/app/api/routes/health.py b/apps/api/app/api/routes/health.py index f897e7f44..644196b32 100644 --- a/apps/api/app/api/routes/health.py +++ b/apps/api/app/api/routes/health.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timezone import psycopg2 import redis @@ -13,7 +13,7 @@ router = APIRouter(tags=["Health"]) async def health_check(): return { "status": "healthy", - "timestamp": datetime.utcnow().isoformat(), + "timestamp": datetime.now(timezone.utc).isoformat(), "version": settings.APP_VERSION, } @@ -33,7 +33,7 @@ async def startup_check(): all_ready = all(check["status"] == "healthy" for check in checks.values()) response = { "status": "started" if all_ready else "starting", - "timestamp": datetime.utcnow().isoformat(), + "timestamp": datetime.now(timezone.utc).isoformat(), "checks": checks, } if not all_ready: diff --git a/packages/application/auth/jwt_service.py b/packages/application/auth/jwt_service.py old mode 100755 new mode 100644 index 2a08bc450..0d7f17b1b --- a/packages/application/auth/jwt_service.py +++ b/packages/application/auth/jwt_service.py @@ -1,6 +1,6 @@ """JWT Token 生成、验证、解析服务""" -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from typing import Any, Dict, Optional import jwt @@ -88,7 +88,7 @@ class JWTService(JWTServicePort): Returns: JWT Token 字符串 """ - now = datetime.utcnow() + now = datetime.now(timezone.utc) expire = now + timedelta(minutes=self.config.ACCESS_TOKEN_EXPIRE_MINUTES) # noqa: E501 payload = { @@ -115,7 +115,7 @@ class JWTService(JWTServicePort): Returns: JWT Token 字符串 """ - now = datetime.utcnow() + now = datetime.now(timezone.utc) expire = now + timedelta(days=self.config.REFRESH_TOKEN_EXPIRE_DAYS) payload = { -- 2.54.0