Kamixitong/check_session.py
2025-11-19 22:49:24 +08:00

32 lines
873 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import sys
sys.path.append('.')
# 尝试加载.env文件
try:
from dotenv import load_dotenv
if load_dotenv():
print("成功加载.env文件")
else:
print("未找到或无法加载.env文件")
except ImportError:
print("python-dotenv未安装跳过.env文件加载")
from app import create_app, db
from sqlalchemy import text
# 创建应用实例
app = create_app('development')
# 检查会话配置
print(f"应用SECRET_KEY: {app.config.get('SECRET_KEY')}")
print(f"会话生命周期: {app.config.get('PERMANENT_SESSION_LIFETIME')}")
# 检查数据库连接
with app.app_context():
try:
# 尝试执行一个简单的查询
result = db.session.execute(text("SELECT 1")).fetchone()
print(f"数据库连接正常: {result}")
except Exception as e:
print(f"数据库连接错误: {e}")