Spaces:
Paused
Paused
File size: 2,349 Bytes
1f82855 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #!/usr/bin/env python3
"""
Simple test for synchronous /solve endpoint
Usage: python test_sync.py <API_URL>
Example: python test_sync.py https://your-space.hf.space
"""
import sys
import requests
def test_sync_solve(base_url):
"""Test the synchronous solve endpoint"""
print("="*60)
print("Testing Synchronous Solve Endpoint")
print("="*60)
print(f"\nAPI URL: {base_url}")
# Test data
url = "https://createvision.ai"
sitekey = "0x4AAAAAAB6qwG1HcvybuFht"
print(f"\nTarget URL: {url}")
print(f"Sitekey: {sitekey}")
print("\nSending request...")
try:
# Make synchronous request
response = requests.get(
f"{base_url}/solve",
params={
"url": url,
"sitekey": sitekey
},
timeout=30 # 30 second timeout
)
print(f"\nStatus Code: {response.status_code}")
result = response.json()
if result.get("success"):
print("\n✅ SUCCESS!")
print(f"Token: {result['token'][:50]}...")
print(f"Elapsed Time: {result['elapsed_time']} seconds")
print(f"\nFull Token:\n{result['token']}")
return True
else:
print("\n❌ FAILED!")
print(f"Error: {result.get('error')}")
print(f"Elapsed Time: {result.get('elapsed_time')} seconds")
return False
except requests.exceptions.Timeout:
print("\n❌ Request timed out (>30 seconds)")
return False
except Exception as e:
print(f"\n❌ Error: {e}")
return False
def main():
if len(sys.argv) < 2:
print("Usage: python test_sync.py <API_URL>")
print("Example: python test_sync.py https://your-space.hf.space")
print("\nOr test locally:")
print(" python test_sync.py http://localhost:7860")
sys.exit(1)
api_url = sys.argv[1].rstrip('/')
success = test_sync_solve(api_url)
print("\n" + "="*60)
if success:
print("✅ Test passed!")
else:
print("❌ Test failed!")
print("="*60)
sys.exit(0 if success else 1)
if __name__ == "__main__":
main()
|