我正在运行以下脚本:从 fastapi 导入 FastAPI从 fastapi 导入 Requestimport osimport uvicornapp = FastAPI()@app.post(\'/\')async def root(data: Request): try:...
我正在运行以下脚本:
from fastapi import FastAPI
from fastapi import Request
import os
import uvicorn
app = FastAPI()
@app.post("/")
async def root(data: Request):
try:
res = await data.json()
except Exception as ex:
res = str(ex)
return res
if __name__ == "__main__":
prog = os.path.basename(__file__).replace(".py","")
uvicorn.run("%s:app" % prog, host="127.0.0.1", port=5000, log_level="debug",reload=True)
并尝试使用以下 cURL 命令进行测试:
curl -d '{"text":"Foo Bar"}' -H "Content-Type: application/json" -X POST http://localhost:5000
我得到的总是:
"Expecting value: line 1 column 1 (char 0)"
这里有什么问题?
Windows 11,Python 3.9.9