Ai_GirlFriend/xuniYou/测试任务382资源.py
2026-03-02 18:57:11 +08:00

124 lines
4.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
测试任务382的图片和音频资源是否可访问
"""
import requests
from urllib.parse import urlparse
# 任务382的资源URL
IMAGE_URL = "https://hello12312312.oss-cn-hangzhou.aliyuncs.com/lover/64/images/1772184154_female.png"
AUDIO_URL = "https://hello12312312.oss-cn-hangzhou.aliyuncs.com/uploads/20260126/eb0d206f4ccd8e38ce1e5f014fcced4e.mp3"
def test_url(url, resource_type):
"""测试URL是否可访问"""
print(f"\n{'='*80}")
print(f"测试 {resource_type}")
print(f"{'='*80}")
print(f"URL: {url}")
try:
# 发送HEAD请求检查资源是否存在
response = requests.head(url, timeout=10, allow_redirects=True)
print(f"状态码: {response.status_code}")
if response.status_code == 200:
print("✅ 资源可访问")
# 获取资源信息
content_type = response.headers.get('Content-Type', 'Unknown')
content_length = response.headers.get('Content-Length', 'Unknown')
print(f"内容类型: {content_type}")
if content_length != 'Unknown':
size_mb = int(content_length) / (1024 * 1024)
print(f"文件大小: {content_length} bytes ({size_mb:.2f} MB)")
# 如果是图片,尝试获取图片信息
if resource_type == "图片" and content_type.startswith('image'):
try:
from PIL import Image
from io import BytesIO
img_response = requests.get(url, timeout=10)
img = Image.open(BytesIO(img_response.content))
print(f"图片尺寸: {img.size[0]} x {img.size[1]}")
print(f"图片格式: {img.format}")
print(f"图片模式: {img.mode}")
except ImportError:
print("提示: 安装 Pillow 可以获取更多图片信息 (pip install Pillow)")
except Exception as e:
print(f"获取图片详细信息失败: {e}")
return True
elif response.status_code == 403:
print("❌ 访问被拒绝403 Forbidden")
print("可能原因:")
print(" - OSS权限配置问题")
print(" - 需要签名访问")
print(" - IP白名单限制")
return False
elif response.status_code == 404:
print("❌ 资源不存在404 Not Found")
print("可能原因:")
print(" - 文件已被删除")
print(" - URL路径错误")
print(" - Bucket名称错误")
return False
else:
print(f"❌ 请求失败,状态码: {response.status_code}")
return False
except requests.exceptions.Timeout:
print("❌ 请求超时")
print("可能原因:")
print(" - 网络连接问题")
print(" - OSS服务响应慢")
return False
except requests.exceptions.ConnectionError as e:
print(f"❌ 连接错误: {e}")
print("可能原因:")
print(" - 网络不可达")
print(" - DNS解析失败")
print(" - 防火墙阻止")
return False
except Exception as e:
print(f"❌ 未知错误: {e}")
return False
def main():
print("="*80)
print("任务382资源可访问性测试")
print("="*80)
# 测试图片
image_ok = test_url(IMAGE_URL, "图片")
# 测试音频
audio_ok = test_url(AUDIO_URL, "音频")
# 总结
print(f"\n{'='*80}")
print("测试总结")
print("="*80)
print(f"图片URL: {'✅ 可访问' if image_ok else '❌ 不可访问'}")
print(f"音频URL: {'✅ 可访问' if audio_ok else '❌ 不可访问'}")
if image_ok and audio_ok:
print("\n✅ 所有资源都可访问,问题可能在其他地方")
print("\n建议检查:")
print(" 1. 查看数据库中的完整错误信息")
print(" 2. 检查用户视频生成次数")
print(" 3. 查看应用日志")
print(" 4. 检查EMO检测结果")
else:
print("\n❌ 部分资源不可访问,这可能是任务失败的原因")
print("\n建议:")
print(" 1. 检查OSS配置和权限")
print(" 2. 确认文件是否存在")
print(" 3. 检查网络连接")
print("\n" + "="*80)
if __name__ == "__main__":
main()