使用 twilio python api

问题描述

当我尝试使用 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 @R_664_4045@ion:

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

More @R_664_4045@ion may be available here:

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

我检查了链接,但是 a) 我不确定问题到底是什么,并且 b) 它没有说明如何修复它。

这是代码

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)

解决方法

account_sidauth_token 应该作为字符串传递,而不是包含字符串的数组。

Twillio Rest Client Source Code

编辑您的代码:

account_sid = 'AC766eaf7ef8d79de658756223cee446df'
auth_token = '74ef4743a7a9a748cxxxxxxxxxxxxxxx'