[英]FastAPI endpoint not receiving post data
Here is the endpoint, at the moment it is the only endpoint because I'm following the FastAPI tutorial.这是端点,目前它是唯一的端点,因为我正在关注 FastAPI 教程。 the print statement only prints {}
.打印语句只打印{}
。
@app.post('/contact', response_model=schemas.Contact)
def create_contact(contact: schemas.ContactCreate, db: Session = Depends(get_db)):
print(contact)
return crud.create_contact(db=db, contact=contact)
This is the contents of the schema.py
file这是schema.py
文件的内容
class ContactBase(BaseModel):
name: str
email: str
subject: str
class ContactCreate(BaseModel):
pass
class Contact(ContactBase):
id: int
class Config:
orm_mode = True
and this is the error that is being throw by the endpoint这是端点抛出的错误
response -> subject回复 -> 主题
none is not an allowed value (type=type_error.none.not_allowed) none 不是允许的值(type=type_error.none.not_allowed)
and this is the post data这是帖子数据
{"name":"bailey","email":"a@a.com","subject":"kjgjhkh"}
I'm not too sure whats going on because I've followed the SQL tutorial on the FastAPI docs and it all looks correct to me.我不太确定发生了什么,因为我遵循了 FastAPI 文档上的 SQL 教程,对我来说这一切看起来都是正确的。 It seems the issue is the endpoint isn't receiving the data from the post request but I'm really not sure why, and it is definitely hitting the endpoint.问题似乎是端点没有从发布请求中接收数据,但我真的不知道为什么,而且它肯定会到达端点。
仔细检查后, ContactCreate
类继承了错误的类,将其更改为ContactBase
类,现在它可以工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.