【发布时间】:2021-08-08 13:28:35
【问题描述】:
我正在编写一个带有字节正文的 python 发布请求:
with open('srt_file.srt', 'rb') as f:
data = f.read()
res = requests.post(url='http://localhost:8000/api/parse/srt',
data=data,
headers={'Content-Type': 'application/octet-stream'})
在服务器部分,我尝试解析正文:
app = FastAPI()
BaseConfig.arbitrary_types_allowed = True
class Data(BaseModel):
data: bytes
@app.post("/api/parse/{format}", response_model=CaptionJson)
async def parse_input(format: str, data: Data) -> CaptionJson:
...
但是,我收到了 422 错误:
{"detail":[{"loc":["body"],"msg":"value is not a valid dict","type":"type_error.dict"}]}
那么我的代码哪里出了问题,我应该如何修复它? 提前谢谢大家帮忙!!
【问题讨论】:
标签: python python-requests fastapi