From f5687c40ac14c9de26aae05579d9fdbacd1a0435 Mon Sep 17 00:00:00 2001 From: heshunme Date: Wed, 20 Nov 2024 22:27:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E4=BA=86=E7=BB=BF=E8=89=B2=E5=8B=BE?= =?UTF-8?q?=E5=8B=BE=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/manage_user.py | 4 ++-- config.py | 3 ++- main.py | 4 +++- test/test_login_reg.py | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/api/manage_user.py b/api/manage_user.py index fcf8be7..bea03b1 100644 --- a/api/manage_user.py +++ b/api/manage_user.py @@ -3,7 +3,7 @@ # @Author : 河瞬 # @FileName: manage_user.py # @Software: PyCharm -from fastapi import HTTPException, APIRouter, Depends, Request +from fastapi import HTTPException, APIRouter, Depends from sqlmodel import select from dependencies import SessionDep, get_current_user @@ -14,7 +14,7 @@ router = APIRouter() # 枚举成员 @router.get("/api/s1/user") -async def list_users(request: Request, session: SessionDep, current_user: User = Depends(get_current_user)): +async def list_users(session: SessionDep, current_user: User = Depends(get_current_user)): if current_user.role != 1: raise HTTPException(status_code=403, detail="Only admin users can list users") diff --git a/config.py b/config.py index cc00044..05ea461 100644 --- a/config.py +++ b/config.py @@ -14,5 +14,6 @@ class Settings(BaseSettings): class Config: env_file = ".env" + if __name__ == '__main__': - print(Settings().ALGORITHM) \ No newline at end of file + print(Settings().ALGORITHM) diff --git a/main.py b/main.py index f7c5867..1cba649 100644 --- a/main.py +++ b/main.py @@ -22,10 +22,12 @@ async def lifespan(app: FastAPI): app = FastAPI(lifespan=lifespan) +# noinspection PyTypeChecker app.add_middleware( CORSMiddleware, # allow_origins=["*"], - allow_origins=["http://localhost:8080","http://localhost:5000"], # 允许所有来源,也可以指定具体的来源,例如 ["http://example.com", "https://example.com"] + allow_origins=["http://localhost:8080", "http://localhost:5000"], + # 允许所有来源,也可以指定具体的来源,例如 ["http://example.com", "https://example.com"] allow_credentials=True, # 允许携带凭证(如cookies) allow_methods=["*"], # 允许所有方法,也可以指定具体的方法,例如 ["GET", "POST", "PUT", "DELETE"] allow_headers=["*"], # 允许所有头部,也可以指定具体的头部,例如 ["Content-Type", "Authorization"] diff --git a/test/test_login_reg.py b/test/test_login_reg.py index 516232f..b0f13a1 100644 --- a/test/test_login_reg.py +++ b/test/test_login_reg.py @@ -18,7 +18,7 @@ def create_db_and_tables(): # 创建一个测试客户端 client = TestClient(app) -session: Session = None +session: Session | None = None class TestLoginReg(unittest.TestCase):