似乎首页能访问,其他的不行

This commit is contained in:
cheney
2026-05-25 11:35:45 +08:00
parent f73419e3eb
commit acbe2d07bf
2 changed files with 33 additions and 9 deletions
+17 -5
View File
@@ -3,6 +3,7 @@ import socket
import threading
import sys
import time
import inspect
TARGET_HOST = 'zentao.sunyard.com.cn'
TARGET_PORT = 9788
@@ -10,12 +11,16 @@ TARGET_PORT = 9788
def log_info(source, message):
"""Log info message"""
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
print("[%s] [INFO] [%s] %s" % (timestamp, source, message))
frame = inspect.currentframe().f_back
line = frame.f_lineno
print("[%s] [INFO] [%s] (line %d) %s" % (timestamp, source, line, message))
def log_error(source, message):
"""Log error message"""
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
print("[%s] [ERROR] [%s] %s" % (timestamp, source, message))
frame = inspect.currentframe().f_back
line = frame.f_lineno
print("[%s] [ERROR] [%s] (line %d) %s" % (timestamp, source, line, message))
def handle_request(b_socket, request_data):
"""Handle a single request from device B"""
@@ -134,8 +139,11 @@ def connect_to_b_device(b_host, b_port):
listen_for_requests(sock)
except ConnectionRefusedError:
log_info("System", "Device B not ready (%s:%d), retrying in 3 seconds..." % (b_host, b_port))
except socket.error as e:
if e.errno == 111 or e.errno == 10061:
log_info("System", "Device B not ready (%s:%d), retrying in 3 seconds..." % (b_host, b_port))
else:
log_error("System", "Connection error: %s" % str(e))
time.sleep(3)
except socket.timeout:
log_info("System", "Connection timeout, retrying in 3 seconds...")
@@ -165,7 +173,11 @@ def main():
print("Device B address:", b_host, ":", b_port)
print("=" * 60)
connect_to_b_device(b_host, b_port)
try:
connect_to_b_device(b_host, b_port)
except KeyboardInterrupt:
log_info("System", "Received Ctrl+C, exiting...")
sys.exit(0)
if __name__ == '__main__':
main()