我正在尝试访问期望多部分形式数据的端点:
{
"budget_id": 0,
"file": "string"
}
带参数content type application/json
。
我可以通过 Postman 访问这个端点,选择一个 JSON 文件。
但是,当我在内存中有一个 JSON 字符串并尝试提交一个httpx
发布请求时,我不确定如何对我的字符串进行编码。
我正在发送一个httpx
帖子:
data = {'budget-id': 9, 'file' = json_string.encode()}.
我收到:
The submitted data was not a file. Check the encoding type on the form.
我需要以json_string
其他方式编码吗?我想如果我把它写到一个文件中然后打开这个文件,我可以让它工作,但我不得不这样做似乎很奇怪。