Ai_GirlFriend/test_sing_history.py

43 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
测试唱歌历史记录 API
"""
import requests
# 配置
BASE_URL = "http://localhost:30101"
TOKEN = "3932cd35-4238-4c3f-ad5c-ad6ce9454e79" # 从日志中获取的 token
def test_sing_history():
"""测试获取唱歌历史记录"""
url = f"{BASE_URL}/sing/history"
headers = {
"Authorization": f"Bearer {TOKEN}"
}
print(f"请求 URL: {url}")
print(f"请求头: {headers}")
response = requests.get(url, headers=headers)
print(f"\n状态码: {response.status_code}")
print(f"响应内容:")
print(response.json())
if response.status_code == 200:
data = response.json()
if data.get("code") == 1:
history_list = data.get("data", [])
print(f"\n✅ 成功获取历史记录,共 {len(history_list)}")
for i, item in enumerate(history_list[:5], 1):
print(f"{i}. {item.get('song_title')} - {item.get('video_url')}")
else:
print(f"\n❌ API 返回错误: {data.get('message')}")
else:
print(f"\n❌ HTTP 错误: {response.status_code}")
if __name__ == "__main__":
test_sing_history()