Spaces:
Paused
Paused
| #!/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() | |