diff --git a/huaweitest.py b/huaweitest.py index d5b3168..b6eaa96 100644 --- a/huaweitest.py +++ b/huaweitest.py @@ -5,12 +5,24 @@ app = FastAPI() @app.get("/") -async def root(): +async def root(request: Request): + # 获取当前时间 + now = datetime.now() + + # 格式化时间为 年-月-日 时:分:秒 的格式 + formatted_now = now.strftime("%Y-%m-%d %H:%M:%S") + print(f"请求IP地址: {request.client.host},请求时间{formatted_now},请求路径: /") return "welcome to fastAPI!" @app.get("/script/getscriparam") -async def getscriparam(): +async def getscriparam(request: Request): + # 获取当前时间 + now = datetime.now() + + # 格式化时间为 年-月-日 时:分:秒 的格式 + formatted_now = now.strftime("%Y-%m-%d %H:%M:%S") + print(f"请求IP地址: {request.client.host},请求时间{formatted_now},请求路径: /") data = { "interaction": { "from": 20, @@ -46,7 +58,7 @@ async def do_success(request: Request): client_host = request.client.host # 打印上报成功的时间和IP地址 - print(f"上报成功时间: {current_time}, IP地址: {client_host}") + print(f"请求IP地址: {client_host},上报成功时间: {current_time}") data = {} return { @@ -57,12 +69,13 @@ async def do_success(request: Request): @app.get("/script/failed") -async def do_failed(reason: str = None, errortype: str = None): +async def do_failed(request: Request, reason: str = None, errortype: str = None): # 获取当前时间 now = datetime.now() # 格式化时间为 年-月-日 时:分:秒 的格式 formatted_now = now.strftime("%Y-%m-%d %H:%M:%S") + print(f"请求IP地址: {request.client.host},请求时间{formatted_now},请求路径: /script/failed") # 假设这里记录失败原因到日志或数据库 print(f"上报失败,Time: {formatted_now}, 失败原因: {reason},失败类型: {errortype}.") # 实际应用中应使用更专业的日志记录方式 return {