2021年1月27日星期三

Convert CURL request to python 3

I have this curl request I would like to convert to 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" }'  

can anyone help me please?

I've tried the following request, but not working :

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)  

I'm having the error message :

<Response [400]>  {"errors":[{"code":21,"description":"JSON is not a valid format"}]}  
https://stackoverflow.com/questions/65929972/convert-curl-request-to-python-3 January 28, 2021 at 09:57AM

没有评论:

发表评论