Today, I encountered an error with fastapi and recorded it. The code is as follows:
from typing import * from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() class User(BaseModel): username:str = None password:str = None @app.get("/user") def hello(user:User): return {"username":user.username, "password": user.password}
The reason is that the get request and the head request cannot put the object into it like this, and other request methods can be used. Change it to:
@app.get("/user") def hello(username:str, password:str): return {"username":username, "password":password}
or:
@app.post("/user") def hello(user:User): return {"username":user.username, "password": user.password}
Read More:
- K8S error validating data: ValidationError(Deployment.spec): missing required field selector
- [Solved] “Field pet in XXX.HelloController required a bean of type ‘XXX.Pet‘ that could not be found.“
- [Solved] MindSpore Error: “TypeError: parse() missing 1 required positional.”
- [Solved] The method getContextPath() from the type HttpServletRequest refers to the missing type String
- ERROR ITMS-90022: “Missing required icon file. [How to Solve]
- SpringBoot IntegratenRedis Annotations and access error: EL1008E: Property or field ‘getListMember‘ cannot be found on object of type
- [Solved] Azkaban Error: Missing required property ‘azkaban.native.lib’
- How to Solve Error: Missing type map configuration or unsupported mapping
- OpenCV(-206:Bad flag (parameter or structure field)) Unrecognized or unsupported array type [How to Solve]
- [Solved] failed to req API:localhost:8848/nacos/v1/ns/instance. code:500 msg: java.net.ConnectException
- [Solved] Error: In the Function of ‘fmt::v8::detail::error_handler::on_error(char const*)’
- Mysql5.7.18.1 Error 1054 (42S22): Unknown Column’password’ In’field List’ When Changing User Password
- [Solved] Error while extracting response for type [] and content type []…
- [Solved] Nacos Start Error: failed to req API:127.0.0.1:8848/nacos/v1/ns/service/list. code:503 msg: server is DOWN now
- Libtorch Error: Expected object of type Variable but found type CUDALongType for argument #2 ‘index’
- Solution to java.lang.IllegalArgumentException: Property’dataSource’ is required
- maven Error: Element ‘dependency’ cannot have character [children], because the type’s content type is
- How to Solve Error: Unsupported field: HourOfDay
- How to Solve Error: Element ‘dependency’ cannot have character [children], because the type’s content type is element-
- Redis use command access exception: (error) noauth authentication required