2023/11/14 22:43:33 - E:\github\sqlai-api\deploy\__init__.py[line:90] - INFO - Web app server start initialize...... 2023/11/14 22:43:33 - E:\github\sqlai-api\deploy\__init__.py[line:77] - INFO - Blueprint / is register 2023/11/14 22:43:33 - E:\github\sqlai-api\deploy\__init__.py[line:77] - INFO - Blueprint /ai is register 2023/11/14 22:43:33 - E:\github\sqlai-api\deploy\__init__.py[line:77] - INFO - Blueprint /upload is register 2023/11/14 22:43:33 - E:\github\sqlai-api\deploy\__init__.py[line:92] - INFO - Web app server end initialize...... 2023/11/14 22:43:33 - E:\github\sqlai-api\deploy\__init__.py[line:90] - INFO - Web app server start initialize...... 2023/11/14 22:43:33 - E:\github\sqlai-api\deploy\__init__.py[line:77] - INFO - Blueprint / is register 2023/11/14 22:43:33 - E:\github\sqlai-api\deploy\__init__.py[line:77] - INFO - Blueprint /ai is register 2023/11/14 22:43:33 - E:\github\sqlai-api\deploy\__init__.py[line:77] - INFO - Blueprint /upload is register 2023/11/14 22:43:33 - E:\github\sqlai-api\deploy\__init__.py[line:92] - INFO - Web app server end initialize...... INFO: Started server process [8816] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://127.0.0.1:54321 (Press CTRL+C to quit) INFO: 127.0.0.1:51422 - "GET /docs HTTP/1.1" 200 OK INFO: 127.0.0.1:51422 - "GET /openapi.json HTTP/1.1" 500 Internal Server Error ERROR: Exception in ASGI application Traceback (most recent call last): File "D:\anaconda\envs\openai\Lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 408, in run_asgi result = await app( # type: ignore[func-returns-value] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda\envs\openai\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 84, in __call__ return await self.app(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda\envs\openai\Lib\site-packages\fastapi\applications.py", line 1106, in __call__ await super().__call__(scope, receive, send) File "D:\anaconda\envs\openai\Lib\site-packages\starlette\applications.py", line 122, in __call__ await self.middleware_stack(scope, receive, send) File "D:\anaconda\envs\openai\Lib\site-packages\starlette\middleware\errors.py", line 184, in __call__ raise exc File "D:\anaconda\envs\openai\Lib\site-packages\starlette\middleware\errors.py", line 162, in __call__ await self.app(scope, receive, _send) File "D:\anaconda\envs\openai\Lib\site-packages\starlette\middleware\cors.py", line 83, in __call__ await self.app(scope, receive, send) File "D:\anaconda\envs\openai\Lib\site-packages\starlette\middleware\cors.py", line 83, in __call__ await self.app(scope, receive, send) File "D:\anaconda\envs\openai\Lib\site-packages\starlette\middleware\exceptions.py", line 79, in __call__ raise exc File "D:\anaconda\envs\openai\Lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__ await self.app(scope, receive, sender) File "D:\anaconda\envs\openai\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 20, in __call__ raise e File "D:\anaconda\envs\openai\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 17, in __call__ await self.app(scope, receive, send) File "D:\anaconda\envs\openai\Lib\site-packages\starlette\routing.py", line 718, in __call__ await route.handle(scope, receive, send) File "D:\anaconda\envs\openai\Lib\site-packages\starlette\routing.py", line 276, in handle await self.app(scope, receive, send) File "D:\anaconda\envs\openai\Lib\site-packages\starlette\routing.py", line 66, in app response = await func(request) ^^^^^^^^^^^^^^^^^^^ File "D:\anaconda\envs\openai\Lib\site-packages\fastapi\applications.py", line 1061, in openapi return JSONResponse(self.openapi()) ^^^^^^^^^^^^^^ File "D:\anaconda\envs\openai\Lib\site-packages\fastapi\applications.py", line 1033, in openapi self.openapi_schema = get_openapi( ^^^^^^^^^^^^ File "D:\anaconda\envs\openai\Lib\site-packages\fastapi\openapi\utils.py", line 475, in get_openapi field_mapping, definitions = get_definitions( ^^^^^^^^^^^^^^^^ File "D:\anaconda\envs\openai\Lib\site-packages\fastapi\_compat.py", line 471, in get_definitions return {}, get_model_definitions( ^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda\envs\openai\Lib\site-packages\fastapi\_compat.py", line 374, in get_model_definitions model_name = model_name_map[model] ~~~~~~~~~~~~~~^^^^^^^ KeyError: <class 'pydantic.main.Body_upload_file_upload_upload_file_post'>
代码:
from fastapi import APIRouter, Path, Query, Request, Response, Form, Cookie, Header, status from fastapi import File, UploadFile from pydantic import BaseModel, Field from typing import Optional, Union, List, Tuple, Dict upload = APIRouter(prefix='/upload', tags=["文件上传"]) @upload.post('/file') async def file_(file: bytes = File(..., title="file", description="小文件单文件上传")): return {"file": file} @upload.post('/files') async def files_(files: List[bytes] = File(..., title="files", description="小文件多文件上传")): for f in files: print(f, len(f)) return {"files": len(files)} @upload.post('/upload_files') async def upload_files(files: List[UploadFile] = File(..., title="files", description="大文件多文件上传")): for f in files: content = await f.read() print(f, len(f), f.filename) return {"files": len(files)}