fix: seed_iaop_menus.py swagger 登录返回裸 GetSwaggerToken(无 code 包装),专用登录方法适配
This commit is contained in:
@@ -65,10 +65,21 @@ class FbaClient:
|
||||
# FastAPI >= 0.13x 将 HTTPBasicCredentials 绑定到 query 参数,
|
||||
# 登录需带 ?username=&password=(Basic 头仍保留,双通道兼容)。
|
||||
q = urllib.parse.urlencode({"username": username, "password": password})
|
||||
d = self._req("POST", f"/auth/login/swagger?{q}",
|
||||
headers={"Authorization": f"Basic {cred}"})
|
||||
self.token = d["data"]["access_token"]
|
||||
print(f"[ok] 登录成功:{username}({d['data']['user']['username']})")
|
||||
# 注意:/auth/login/swagger 返回裸 GetSwaggerToken(无 {code,msg} 包装),
|
||||
# 不能走 _req 的通用 code==200 校验。
|
||||
req = urllib.request.Request(
|
||||
f"{self.base}/auth/login/swagger?{q}",
|
||||
headers={"Content-Type": "application/json",
|
||||
"Authorization": f"Basic {cred}"},
|
||||
method="POST")
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=15) as r:
|
||||
d = json.loads(r.read().decode())
|
||||
except urllib.error.HTTPError as e:
|
||||
detail = e.read().decode(errors="replace")[:300]
|
||||
raise SystemExit(f"[fail] POST /auth/login/swagger → HTTP {e.code}: {detail}")
|
||||
self.token = d["access_token"]
|
||||
print(f"[ok] 登录成功:{username}({d['user']['username']})")
|
||||
|
||||
def _req(self, method: str, path: str, body=None, headers=None):
|
||||
h = {"Content-Type": "application/json"}
|
||||
|
||||
Reference in New Issue
Block a user