Add API test script for debugging
This commit is contained in:
36
test_api.py
Normal file
36
test_api.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import socket
|
||||||
|
import json
|
||||||
|
|
||||||
|
HOST = '127.0.0.1'
|
||||||
|
PORT = 4028
|
||||||
|
|
||||||
|
def send_command(command):
|
||||||
|
try:
|
||||||
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
s.settimeout(2)
|
||||||
|
s.connect((HOST, PORT))
|
||||||
|
s.send(json.dumps({"command": command}).encode('utf-8'))
|
||||||
|
|
||||||
|
response = ""
|
||||||
|
while True:
|
||||||
|
data = s.recv(4096)
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
response += data.decode('utf-8').replace('\x00', '')
|
||||||
|
s.close()
|
||||||
|
return response
|
||||||
|
except Exception as e:
|
||||||
|
return f"Error: {e}"
|
||||||
|
|
||||||
|
print("=== Testing API Connection ===")
|
||||||
|
print(f"Connecting to {HOST}:{PORT}")
|
||||||
|
|
||||||
|
print("\n--- Command: summary ---")
|
||||||
|
print(send_command("summary"))
|
||||||
|
|
||||||
|
print("\n--- Command: devs ---")
|
||||||
|
print(send_command("devs"))
|
||||||
|
|
||||||
|
print("\n--- Command: stats ---")
|
||||||
|
print(send_command("stats"))
|
||||||
|
|
||||||
Reference in New Issue
Block a user