【发布时间】:2022-08-08 02:15:13
【问题描述】:
使用 FastAPI同步,而不是异步模式,我希望能够接收原始的、未更改的发布请求正文。
我能找到的所有示例都显示异步代码,当我以正常同步方式尝试时,request.body() 将 uo 显示为协程对象。
当我通过向该端点发布一些 XML 来测试它时,我得到一个 500 \"Internal Server Error\"
from fastapi import FastAPI, Response, Request, Body
app = FastAPI()
@app.get(\"/\")
def read_root():
return {\"Hello\": \"World\"}
@app.post(\"/input\")
def input_request(request: Request):
# how can I access the RAW request body here?
body = request.body()
# do stuff with the body here
return Response(content=body, media_type=\"application/xml\")
这对 FastAPI 来说是不可能的吗?
注意:简化的输入请求看起来像
POST http://127.0.0.1:1083/input
Content-Type: application/xml
<XML>
<BODY>TEST</BODY>
</XML>
而且我无法控制输入请求的发送方式,因为我需要替换现有的 SOAP API