Reputation: 55
I am struggling with this HTTP POST in the requests library in Python. I cannot format the following HTTP POST request for a Python script:
curl -X POST https://api.twilio.com/2010-04-01/Accounts/ACauth_code/Messages.json \
--data-urlencode "To=whatsapp:+1111111111” \
--data-urlencode "From=whatsapp:+111111111” \
--data-urlencode "Body=Thanks for contacting me on WhatsApp! Here is a picture of an owl." \
--data-urlencode "MediaUrl=https://demo.twilio.com/owl.png" \
-u 'ACauth_code:auth_token
Could someone help me format this for the Python requests library?
Thank you in advance!!
Upvotes: 1
Views: 195
Reputation: 5476
import requests
url = "https://api.twilio.com/2010-04-01/Accounts/AC_user/Messages.json"
params = {
"To" : "whatsapp:+111111111",
"From" : "whatsapp:+11111111",
"Body" : "Thanks for contacting me on WhatsApp! Here is a picture of an owl.",
"MediaUrl" : "https://demo.twilio.com/owl.png"
}
res = requests.post(url, params, auth=('AC_user','password/token'))
res = res.json()
Upvotes: 2