{"detail":[{"loc":["body"],"msg":"value is not a valid dict","type":"type_error.dict"}]} 问题分析 作为对比,使用Python的requests库替代Postman发送请求: importjsonimportrequests# 读取 JSON 文件中的数据withopen('./input/input-time-schedule.json')asjson_file:data=json.load(json_file)# ...
[422]>.status_code test.py:16: AssertionError --- Captured stdout call --- b'{"detail":[{"loc":["body"],"msg":"value is not a valid list","type":"type_error.list"}]}' === 1 failed in 0.17s === but there is
{"loc": ["path","item_id"],"msg":"value is not a valid integer","type":"type_error.integer"} ] } 而重写handler后会返回字符串: 1validationerrorpath -> item_id valueisnota validinteger(type=type_error.integer) 如果不想改动默认handler,只是补充点信息,可以导入http_exception_handler和reque...
当传参类型不匹配时,接口定义是:int ➜ curl http://127.0.0.1:8000/demo/path/hello {"detail":[{"loc":["path","order_id"],"msg":"value is not a valid integer","type":"type_error.integer"}]} # 当什么都不传时➜ curl http://127.0.0.1:8000/demo/path/ {"detail":"Not Found"...
), cityIds: List[str] = Body(...), files: List[UploadFile] = File(None) ): 当我使用 form-data 邮递员的选项发送请求时,它显示 0:value is not a valid dict 对于policyDetails 参数。我正在发送 [{"name":"name1","department":"d1"}] 。它说 not a valid dict ,即使我发送了有效的...
valueisnota valid integer (type=type_error.integer) RequestValidationError 源码分析 RequestValidationError 相关源码 classRequestValidationError(ValidationError):def__init__(self, errors:Sequence[ErrorList], *, body:Any=None) ->None: self.body = bodysuper().__init__(errors, RequestErrorModel) ...
"detail": [ { "loc": [ "path", "item_id" ], "msg": "value is not a valid integer", "type": "type_error.integer" } ]} 传float也会报错: "the current user"}: from fastapi import FastAPIapp = FastAPI()@app.get("/users/me")async def read_user_me(...
1 validation errorpath -> item_idvalue is not a valid integer (type=type_error.integer) RequestValidationErrorvsValidationError¶ 警告 如果您觉得现在还用不到以下技术细节,可以先跳过下面的内容。 RequestValidationError是 Pydantic 的ValidationError的子类。
value is not a valid integer (type=type_error.integer) 1. 2. 3. 4. 5. 6. 7. 8. 9. RequestValidationError 源码分析 RequestValidationError 相关源码 class RequestValidationError(ValidationError): def __init__(self, errors: Sequence[ErrorList], *, body: Any = None) -> None: ...
"msg": "value is not a valid integer", "type": "type_error.integer" To reproduce, just run this and call then endpoint using the OpenApi ui: from typing import List from fastapi import FastAPI, Form app = FastAPI() @app.post("/items") async def create_item( list_int: List[int...