pythontwiliotwilio-apitwilio-python

Getting error making calls with twilio python api


Getting this error when I try to make a call with the twilio python api:

Jacob-Mac-mini:downloads kovyjacob$ python3 twilio_call.py
Traceback (most recent call last):
  File "/Users/kovyjacob/Downloads/twilio_call.py", line 11, in <module>
    call = client.calls.create(
  File "/Users/kovyjacob/Library/Python/3.9/lib/python/site-packages/twilio/rest/api/v2010/account/call/__init__.py", line 141, in create
    payload = self._version.create(method='POST', uri=self._uri, data=data, )
  File "/Users/kovyjacob/Library/Python/3.9/lib/python/site-packages/twilio/base/version.py", line 205, in create
    raise self.exception(method, uri, response, 'Unable to create record')
twilio.base.exceptions.TwilioRestException: 
HTTP Error Your request was:

POST /Accounts/['AC766eaf7ef8d79de658756223cee446df']/Calls.json

Twilio returned the following information:

Unable to create record: The requested resource /2010-04-01/Accounts/['AC766eaf7ef8d79de658756223cee446df']/Calls.json was not found

More information may be available here:

https://www.twilio.com/docs/errors/20404

I checked the link, but a) I'm not sure what the problem is exactly, and b) it doesn't say how to fix it.

This is the code:

from twilio.rest import Client


# Your Account Sid and Auth Token from twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ['AC766eaf7ef8d79de658756223cee446df']
auth_token = ['74ef4743a7a9a748cxxxxxxxxxxxxxxx']
client = Client(account_sid, auth_token)

call = client.calls.create(
                        twiml='<Response><Say>Ahoy, World!</Say></Response>',
                        to='+14372341004',
                        from_='+14243560675'
                    )

print(call.sid)

Solution

  • account_sid and auth_token should be passed as strings, not array with string inside.

    Twillio Rest Client Source Code

    Edit your code to:

    account_sid = 'AC766eaf7ef8d79de658756223cee446df'
    auth_token = '74ef4743a7a9a748cxxxxxxxxxxxxxxx'