fix: 修复邀请码注册时 _parse_datetime 类型处理问题
- MySQL 返回的 datetime 可能是 date 类型 - _parse_datetime 现在能正确处理 date 类型 - 修复注册接口 500 错误 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -531,13 +531,20 @@ def add_user(user: User) -> int:
|
||||
return cursor.lastrowid
|
||||
|
||||
|
||||
def _parse_datetime(value) -> datetime:
|
||||
def _parse_datetime(value) -> Optional[datetime]:
|
||||
"""将字符串或 datetime 转换为 datetime 对象"""
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, datetime):
|
||||
return value
|
||||
return datetime.fromisoformat(value)
|
||||
# MySQL 可能返回 date 类型
|
||||
if isinstance(value, date):
|
||||
return datetime.combine(value, datetime.min.time())
|
||||
# 尝试解析字符串
|
||||
try:
|
||||
return datetime.fromisoformat(value)
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
|
||||
|
||||
def _parse_date(value) -> date:
|
||||
|
||||
@@ -79,6 +79,12 @@ class QwenVisionAnalyzer:
|
||||
headers=headers,
|
||||
json=payload,
|
||||
)
|
||||
# 处理认证错误
|
||||
if response.status_code == 401:
|
||||
raise ValueError(
|
||||
"API Key 无效或已过期。请检查 DashScope API Key 是否正确配置。"
|
||||
"可以在管理页面设置 API Key,或通过环境变量 DASHSCOPE_API_KEY 配置。"
|
||||
)
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
|
||||
@@ -135,6 +141,12 @@ class QwenVisionAnalyzer:
|
||||
headers=headers,
|
||||
json=payload,
|
||||
)
|
||||
# 处理认证错误
|
||||
if response.status_code == 401:
|
||||
raise ValueError(
|
||||
"API Key 无效或已过期。请检查 DashScope API Key 是否正确配置。"
|
||||
"可以在管理页面设置 API Key,或通过环境变量 DASHSCOPE_API_KEY 配置。"
|
||||
)
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user