将 cURL 转换为 Python 请求
问题描述:
我需要将以下 cURL 命令转换为 python 请求.
I need to convert the following cURL command to python requests.
curl 'https://test.com/api/v1/courses/xx/discussion_topics/xx/entries.json' \
-F 'message=<message>' \
-H "Authorization: Bearer <token>"
到目前为止我有 requests.post("https://test.com/api/v1/courses/xx/discussion_topics/xx/entries")
但是如何添加消息和身份验证?
So far I have requests.post("https://test.com/api/v1/courses/xx/discussion_topics/xx/entries")
but how do I add the message and auth?
答
requests.post("https://test.com/api/v1/courses/xx/discussion_topics/xx/entries.json, data=json.dumps({"message": "<message>"}), headers={"Authorization": "Bearer <token>"})