From 635ae720b9a2a66a9f75f24c2efd4a0f387f32ad Mon Sep 17 00:00:00 2001 From: helloplhm-qwq Date: Sun, 24 Dec 2023 10:47:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=97=A5=E5=BF=97=E6=97=B6=E5=87=BA=E7=8E=B0=E7=9A=84?= =?UTF-8?q?=20'str'=20object=20has=20no=20attribute=20'status'=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.py b/main.py index 2b757e1..cb769b6 100644 --- a/main.py +++ b/main.py @@ -70,6 +70,12 @@ async def handle_before_request(app, handler): return handleResult({'code': 6, 'msg': '未找到您所请求的资源', 'data': None}, 404) resp = await handler(request) + if (isinstance(resp, str)): + resp = Response(body = resp, content_type='text/plain', status = 200) + elif (isinstance(resp, dict): + resp = handleResult(resp) + elif (not isinstance(resp, Response)): + resp = Response(body = str(resp), content_type='text/plain', status = 200) aiologger.info(f'{request.remote_addr} - {request.method} "{request.path}", {resp.status}') return resp except: