-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
35 lines (30 loc) · 964 Bytes
/
test_api.py
File metadata and controls
35 lines (30 loc) · 964 Bytes
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
import requests
import json
# The URL of our running Flask API
API_URL = "http://127.0.0.1:5000/predict"
# Sample data for a single prediction (a normal-looking data point)
# This simulates a real-time reading from a sensor network.
sample_data = {
"CO(GT)": 2.0,
"PT08.S1(CO)": 1300.0,
"NMHC(GT)": 100.0,
"C6H6(GT)": 10.0,
"PT08.S2(NMHC)": 950.0,
"NOx(GT)": 150.0,
"PT08.S3(NOx)": 1100.0,
"NO2(GT)": 100.0,
"PT08.S4(NO2)": 1600.0,
"PT08.S5(O3)": 1200.0,
"T": 15.0,
"RH": 50.0,
"AH": 0.8
}
# Send the POST request to the API
try:
response = requests.post(API_URL, json=sample_data)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
# Pretty-print the JSON response from the server
print("✅ API Response:")
print(json.dumps(response.json(), indent=4))
except requests.exceptions.RequestException as e:
print(f"❌ Could not connect to the API: {e}")