Hoping the stackoverflow community will help me out. I want to send sms using the POST api in python, here's what i have tried:
>> post_data = {"To": "my-phone-number", "From": TWILIO_NUMBER, "Body": "Test message", "AccountSid": "my-account-sid", "AuthToken":"my-auth-token"}
>> import requests
>> response = requests.post('https://api.twilio.com/2010-04-01/Accounts/my-account-sid/Messages', data=post_data)
I get the following error:
response.content
"<?xml version='1.0' encoding='UTF-8'?>\n<TwilioResponse><RestException><Code>20003</Code><Detail>Your AccountSid or AuthToken was incorrect.</Detail><Message>Authentication Error - No credentials provided</Message><MoreInfo>https://www.twilio.com/docs/errors/20003</MoreInfo><Status>401</Status></RestException></TwilioResponse>"
I even tried this request URI:
>> response = requests.post('https://api.twilio.com/2010-04-01/Accounts/my-account-sid:my-auth-token/Messages', data=post_data)
Still the same error :-/
Is my uri wrong or the POST parameters incomplete ? Documentation is not great honestly for the POST api :-/
Update: Anyone who is still looking for answers, you can either see the accepted answer or update the request as shown below:
response = requests.post('https://api.twilio.com/2010-04-01/Accounts/my-account-sid/Messages', data=post_data, auth=('my-account-sid', 'my-auth-token'))