good version for 算法注册
This commit is contained in:
53
backend/test_login_api.py
Normal file
53
backend/test_login_api.py
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
"""直接测试登录API"""
|
||||
|
||||
import requests
|
||||
|
||||
def test_login_api():
|
||||
"""测试登录API"""
|
||||
base_url = "http://localhost:8001/api/v1"
|
||||
|
||||
# 测试1: 使用JSON格式
|
||||
print("测试1: 使用JSON格式")
|
||||
login_data = {
|
||||
"username": "admin",
|
||||
"password": "admin123"
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(f"{base_url}/users/login", json=login_data)
|
||||
print(f"状态码: {response.status_code}")
|
||||
print(f"响应头: {dict(response.headers)}")
|
||||
print(f"响应内容: {response.text[:500]}")
|
||||
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
print(f"✅ 登录成功!")
|
||||
print(f"Token: {data.get('access_token', 'N/A')[:50]}...")
|
||||
else:
|
||||
print(f"❌ 登录失败")
|
||||
except Exception as e:
|
||||
print(f"错误: {e}")
|
||||
|
||||
# 测试2: 使用form-data格式
|
||||
print("\n\n测试2: 使用form-data格式")
|
||||
form_data = {
|
||||
"username": "admin",
|
||||
"password": "admin123"
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(f"{base_url}/users/login", data=form_data)
|
||||
print(f"状态码: {response.status_code}")
|
||||
print(f"响应内容: {response.text[:500]}")
|
||||
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
print(f"✅ 登录成功!")
|
||||
else:
|
||||
print(f"❌ 登录失败")
|
||||
except Exception as e:
|
||||
print(f"错误: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_login_api()
|
||||
Reference in New Issue
Block a user