fix: Unicode syntax error в start_server.py

Проблема: bytes literal с Unicode символами (🔐, ╔, ║ и т.д.)

Решение:
- HTML response через .encode('utf-8') вместо bytes literal
- ASCII box drawing вместо Unicode символов
- Убраны emoji из print statements

Тест:
  python3 -m py_compile web-client/start_server.py
This commit is contained in:
2026-05-21 14:09:54 +03:00
parent fc816ed7b3
commit 168ec73b7c
+30 -24
View File
@@ -60,15 +60,16 @@ class AuthHandler(http.server.SimpleHTTPRequestHandler):
self.send_header('Content-type', 'text/html; charset=utf-8') self.send_header('Content-type', 'text/html; charset=utf-8')
self.end_headers() self.end_headers()
self.wfile.write(b''' html = '''
<html> <html>
<head><title>401 Unauthorized</title></head> <head><title>401 Unauthorized</title></head>
<body> <body>
<h1>🔐 Wyoming Satellite — Authentication Required</h1> <h1>Wyoming Satellite - Authentication Required</h1>
<p>Please enter the password to access the Web UI.</p> <p>Please enter the password to access the Web UI.</p>
</body> </body>
</html> </html>
''') '''
self.wfile.write(html.encode('utf-8'))
def do_GET(self): def do_GET(self):
"""Handle GET requests with authentication.""" """Handle GET requests with authentication."""
@@ -111,45 +112,50 @@ def main():
# Create handler with password # Create handler with password
Handler = create_auth_handler(args.password) Handler = create_auth_handler(args.password)
print(f""" print("""
╔══════════════════════════════════════════════════════════╗ +==========================================================+
║ 🛰️ Wyoming Satellite WebSocket Client Server ║ | Wyoming Satellite WebSocket Client Server |
╠══════════════════════════════════════════════════════════╣ +==========================================================+
║ Serving: {str(SCRIPT_DIR):<45} ║ | Serving: {:<53} |
║ URL: http://localhost:{args.port:<36} ║ | URL: http://localhost:{:<29} |
║ Remote: http://<your-ip>:{args.port:<32} ║ | Remote: http://<your-ip>:{:<25} |
║ Password: {'*' * len(args.password):<45} ║ | Password: {:<48} |
║ ║ | |
║ Press Ctrl+C to stop ║ | Press Ctrl+C to stop |
╚══════════════════════════════════════════════════════════╝ +==========================================================+
""") """.format(
str(SCRIPT_DIR),
args.port,
args.port,
'*' * len(args.password)
))
try: try:
with ReusableTCPServer((args.host, args.port), Handler) as httpd: with ReusableTCPServer((args.host, args.port), Handler) as httpd:
print(f"🚀 Server started on http://{args.host}:{args.port}") print(f"Server started on http://{args.host}:{args.port}")
print("📖 Serving files from:", SCRIPT_DIR) print("Serving files from:", SCRIPT_DIR)
print(f"🔐 Password protected ({len(args.password)} characters)") print(f"Password protected ({len(args.password)} characters)")
print("\n⌨️ Press Ctrl+C to stop\n") print("\nPress Ctrl+C to stop\n")
try: try:
httpd.serve_forever() httpd.serve_forever()
except KeyboardInterrupt: except KeyboardInterrupt:
print("\n👋 Shutting down gracefully...") print("\nShutting down gracefully...")
# Shutdown in a separate thread to avoid deadlock # Shutdown in a separate thread to avoid deadlock
shutdown_thread = threading.Thread(target=httpd.shutdown) shutdown_thread = threading.Thread(target=httpd.shutdown)
shutdown_thread.start() shutdown_thread.start()
shutdown_thread.join(timeout=2) shutdown_thread.join(timeout=2)
httpd.server_close() httpd.server_close()
print("✅ Server stopped successfully") print("Server stopped successfully")
except OSError as e: except OSError as e:
print(f"\n❌ Error: Could not bind to port {args.port}") print(f"\nError: Could not bind to port {args.port}")
print(f" {e}") print(f" {e}")
print("\n💡 Try using a different port:") print("\nTry using a different port:")
print(f" python3 {sys.argv[0]} --port 8081\n") print(f" python3 {sys.argv[0]} --port 8081\n")
sys.exit(1) sys.exit(1)
except Exception as e: except Exception as e:
print(f"\n❌ Unexpected error: {e}") print(f"\nUnexpected error: {e}")
sys.exit(1) sys.exit(1)