Python请求 - 编码Form -Data
我想在请求中复制以下卷曲调用:
curl --request POST 'https://my_api.com/request/dynamic_views' \
--header 'Cookie: session=123' \
--form 'data="{\"searchId\":66966,\"mapAllTeam\":true}"'
我的表单项目有问题,需要作为多部分/form-data提供。
我正在尝试以下(简化的代码):
uri="https://my_api.com/request/dynamic_views"
session_cookie = {"Cookie":"session=123"}
file = {"data": '"{\"searchId\":66966,\"mapAllTeam\":true }"'}
response = requests.post(uri, headers=session_cookie, files=file )
我得到的响应是:
reply: 'HTTP/1.1 400 \r\n'
[...]
{'status': 'Success', 'message': 'Missing required data, Please enter proper Data.'}
这表明表格已被错误附加。
I would like to replicate following curl call in requests:
curl --request POST 'https://my_api.com/request/dynamic_views' \
--header 'Cookie: session=123' \
--form 'data="{\"searchId\":66966,\"mapAllTeam\":true}"'
I have a problem with form item which need to be provided as multipart/form-data.
I'm trying the following(simplified code):
uri="https://my_api.com/request/dynamic_views"
session_cookie = {"Cookie":"session=123"}
file = {"data": '"{\"searchId\":66966,\"mapAllTeam\":true }"'}
response = requests.post(uri, headers=session_cookie, files=file )
Response I got is:
reply: 'HTTP/1.1 400 \r\n'
[...]
{'status': 'Success', 'message': 'Missing required data, Please enter proper Data.'}
Which indicates that form has been incorrectly attached.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它必须看起来像
It has to look like