8000 Update http_file_server.py · qfcy/python-http-server@31fd33c · GitHub
[go: up one dir, main page]

Skip to content

Commit 31fd33c

Browse files
committed
Update http_file_server.py
1 parent 5626584 commit 31fd33c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

http_file_server.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def close(self):
100100
stream.close()
101101

102102
def log_addr(*args, sep=" ", file=None, flush=False): # 带时间和IP地址、端口的日志记录
103-
print(f"{time.asctime()} | {cur_address[0]}:{cur_address[1]}{sep}{sep.join(args)}",
103+
print(f"""{time.asctime()} | {cur_address[0]}:\
104+
{cur_address[1]}{sep}{sep.join(str(arg) for arg in args)}""",
104105
file=file,flush=flush)
105106

106107

@@ -435,7 +436,9 @@ def handle_get(req_head,req_info):
435436
return getcontent(direc,query,fragment) # 获取目录的数据
436437

437438
def handle_client(sock, address):# 处理客户端请求
438-
raw = sock.recv(RECV_LENGTH)
439+
try:raw = sock.recv(RECV_LENGTH)
440+
except ConnectionError as err:
441+
log_addr("连接异常 (%s): %s" % (type(err).__name__,str(err)))
439442
if not raw:return # 忽略空数据
440443

441444
req_head,req_info = get_request_info(raw)

0 commit comments

Comments
 (0)
0