-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_web_server.py
More file actions
executable file
·37 lines (32 loc) · 1.45 KB
/
test_web_server.py
File metadata and controls
executable file
·37 lines (32 loc) · 1.45 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
import requests
import sys
# Use the standard port configured in app.py
WEB_SERVER_PORT = 5000
url = f'http://127.0.0.1:{WEB_SERVER_PORT}/'
print(f"Attempting to access web server at: {url}")
print("(Requires the 'python app.py' process to be running)")
try:
response = requests.get(url, timeout=10)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
# Check for a key element from the HTML (e.g., the title)
# Update this if you changed the title in index.html
if "<title>Drone Control Interface</title>" in response.text:
print("SUCCESS: Web server is running and responded with expected content.")
sys.exit(0)
else:
print("FAILED: Web server responded, but the content seems incorrect.")
print(" (Check if the correct index.html is being served)")
# Optionally print some response text for debugging:
# print("\nResponse Text (first 500 chars):\n", response.text[:500])
sys.exit(1)
except requests.exceptions.ConnectionError:
print(f"FAILED: Could not connect to the server at {url}.")
print(" Is the 'python app.py' script running?")
sys.exit(1)
except requests.exceptions.Timeout:
print(f"FAILED: The request timed out.")
print(" Is the 'python app.py' script running and responsive?")
sys.exit(1)
except requests.exceptions.RequestException as e:
print(f"FAILED: An error occurred while accessing the web server: {e}")
sys.exit(1)