-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_connection.py
More file actions
40 lines (31 loc) · 1.07 KB
/
test_api_connection.py
File metadata and controls
40 lines (31 loc) · 1.07 KB
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
import requests
import os
API_URL = "http://localhost:8000"
API_KEY = "multimodal-admin-key"
def test_api():
print("--- Testing API Connection ---")
# 1. Health Check
try:
resp = requests.get(f"{API_URL}/")
print(f"Health Check: {resp.status_code} - {resp.text}")
except Exception as e:
print(f"❌ Health Check FAILED: {e}")
return
# 2. Upload Test
print("\n--- Testing Upload ---")
# Create dummy file
with open("temp_test_doc.txt", "w") as f:
f.write("This is a test document.")
try:
files = {'file': open("temp_test_doc.txt", 'rb')}
headers = {'x-api-key': API_KEY}
resp = requests.post(f"{API_URL}/upload", files=files, headers=headers)
print(f"Upload: {resp.status_code}")
print(f"Response: {resp.text}")
except Exception as e:
print(f"❌ Upload FAILED: {e}")
finally:
files['file'].close()
os.remove("temp_test_doc.txt")
if __name__ == "__main__":
test_api()