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