首页 > 解决方案 > 为什么我不能在 FastApi swagger ui 中授权 api 调用,其中可以使用 postman 授权和调用相同的 api?

问题描述

我开始用 FastApi 编程。它带有一个内置的 swagger 接口,可以与我的代码中的 api 进行交互。我已经完成了数据库中用户的身份验证和授权。但是 swagger 并没有授权我的数据库中的用户使用邮递员获得授权。swagger ui 授权表单显示“用户名”和“密码”,我的表将“电话号码”作为唯一字段。

模型.py

from sqlalchemy import Column, String, BigInteger, Integer from utils.database import Base

类 UserModel(Base): tablename = "user"

id = Column(BigInteger, primary_key=True, index=True)
phoneNumber = Column(Integer, unique=True, index=True)
password = Column(String, index=True)
type = Column(String, index=True)

标签: pythonswaggerswagger-uiswagger-2.0fastapi

解决方案


推荐阅读