惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
Engineering at Meta
Engineering at Meta
有赞技术团队
有赞技术团队
月光博客
月光博客
M
MIT News - Artificial intelligence
V
Visual Studio Blog
Stack Overflow Blog
Stack Overflow Blog
阮一峰的网络日志
阮一峰的网络日志
D
DataBreaches.Net
I
InfoQ
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
雷峰网
雷峰网

博客园 - 小默同学

C语言文件操作 makefile 文件的写法 tkinter教程 基本黑客技术 window下开机自启动.bat文件和后台启动.bat文件 django 用 uvicorn 部署 python 声音去噪处理 basis of PHP DBMA about mysql 免费文字转语音工具 折半查找python代码实现 c:\windows\temp\ccvjvr7w.o:problemfour.cpp:(.text+0x17): undefined reference to `std::basic_istream< - 小默同学 Android连接第三方模拟器 vscode下搭建springboot python jwt 一篇文章极速复习drf知识点 LCD1602代码记录 外部排序 防止win10系统把破解软件当成病毒自动删除keil的破解软件 ERROR 1366 (HY000): Incorrect string value: '\xC4\xE3\xBA\xC3' for column 'p - 小默同学
{&quot;detail&quot;:[{&quot;loc&quot;:[&quot;body&quot;],...
小默同学 · 2022-09-09 · via 博客园 - 小默同学

今天用fastapi遇到了一个错误记录一下,代码如下:

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}

原因是get请求和head请求不能够这样放对象进入好像,用其他请求方式就可以了。改为:

@app.get("/user")
def hello(username:str, password:str):
	return {"username":username, "password":password}

或者:

@app.post("/user")
def hello(user:User):
    return {"username":user.username, "password": user.password}