import socket def test_port_binding(host, port): try: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind((host, port)) print(f"成功绑定到 {host}:{port}") except PermissionError: print(f"绑定到 {host}:{port} 时权限不足") except Exception as e: print(f"绑定到 {host}:{port} 时发生错误: {e}") # 测试绑定 test_port_binding("127.0.0.1", 3000) test_port_binding("0.0.0.0", 3000) from flask import Flask app = Flask(__name__) if __name__ == '__main__': app.run(host="127.0.0.1", port=3000) # HTTPS required for secure cookies