ohmycaptcha / test_deployment.py
zzdccww's picture
🚀 Deploy ohmycaptcha via Automation Tool
1c70457 verified
import urllib.request
import json
import sys
BASE_URL = "https://zzdccww-zzdccww-ohmycaptcha.hf.space"
CLIENT_KEY = "cww"
def test_health():
url = f"{BASE_URL}/api/v1/health"
print(f"[{url}]")
print("正在请求健康检查接口...")
try:
req = urllib.request.Request(url)
with urllib.request.urlopen(req, timeout=30) as resp:
data = resp.read().decode('utf-8')
print(f"状态码: {resp.getcode()}")
print(f"响应内容: {data}")
return resp.getcode() == 200
except Exception as e:
print(f"请求发生异常: {e}")
return False
def test_create_task():
url = f"{BASE_URL}/createTask"
print(f"\n[{url}]")
print("正在验证核心打码功能,发送模拟任务 (HCaptcha验证码)...")
payload = {
"clientKey": CLIENT_KEY,
"task": {
"type": "HCaptchaTaskProxyless",
"websiteURL": "https://example.com",
"websiteKey": "10000000-ffff-ffff-ffff-000000000001"
}
}
data = json.dumps(payload).encode('utf-8')
req = urllib.request.Request(url, data=data, headers={"Content-Type": "application/json"})
try:
with urllib.request.urlopen(req, timeout=30) as resp:
resp_data = resp.read().decode('utf-8')
print(f"状态码: {resp.getcode()}")
print(f"响应内容: {resp_data}")
if resp.getcode() == 200 and "taskId" in resp_data:
print("任务创建成功,服务端已返回 taskId。")
else:
print("任务没有返回预期结果,请检查服务端日志。")
except urllib.error.HTTPError as e:
print(f"请求发生 HTTP 异常: {e.code} - {e.read().decode('utf-8')}")
except Exception as e:
print(f"请求发生异常: {e}")
if __name__ == "__main__":
if test_health():
print("\n健康检查通过,容器已经成功在 Hugging Face 跑起来了。")
test_create_task()
else:
print("\n服务目前还未就绪。可能是刚上传完,容器仍在安装 Playwright 依赖并构建;也可能是构建失败。可以直接打开页面查看构建日志。")
sys.exit(1)