我的FastAPI主要功能代码如下:
class Prompt(BaseModel):
content: str = ""
@app.post("/query")
def query_item(prompt: Prompt = None):
return promt
当我尝试使用curl发送我的帖子请求时
curl -X POST "http://localhost:8000/query" -d '{"content":"Hello"}'
响应显示 Input should be a valid dictionary or object to extract fields from
需要帮助
我尝试使用请求包并在请求中发送显式字典,但问题仍然存在
您需要告诉
curl
使用 application/json
作为内容类型:
λ curl -X POST "http://localhost:8111/query" -H "Content-Type: application/json" -d "{\"content\":\"Hello\"}"
{"content":"Hello"}
(并且您需要将
return promt
更改为 return prompt
)