【发布时间】:2021-01-28 01:57:33
【问题描述】:
我有这个 curl 请求,我想转换为 python 3
curl -X "POST" "https://conversations.messagebird.com/v1/send" \\
-H "Authorization: AccessKey YOUR-API-KEY" \\
-H "Content-Type: application/json" \\
--data '{ "to":"+31XXXXXXXXX", "from":"WHATSAPP-CHANNEL-ID", "type":"text", "content":{ "text":"Hello!" }, "reportUrl":"https://example.com/reports" }'
谁能帮帮我?
我尝试了以下请求,但没有工作:
import requests
header = {"Authorization":"AccessKey YOUR-API-KEY"}
data = { "to":"+31XXXXXXXXX", "from":"WHATSAPP-CHANNEL-ID", "type":"text", "content":{"text":"Hello!" }, "reportUrl":"https://example.com/reports"}
url = 'https://conversations.messagebird.com/v1/send'
response = requests.post(url, data=data, headers=header)
print(response.text)
我收到错误消息:
<Response [400]>
{"errors":[{"code":21,"description":"JSON is not a valid format"}]}
【问题讨论】:
-
这能回答你的问题吗? How to POST JSON data with Python Requests?