Python 属性错误:';模块';对象没有属性';Twiliorest客户机';
尝试将django 1.10应用程序与twilio 6.0.0和django twilio==0.8.0集成 提及 在我的shell中显示错误Python 属性错误:';模块';对象没有属性';Twiliorest客户机';,python,django,twilio,Python,Django,Twilio,尝试将django 1.10应用程序与twilio 6.0.0和django twilio==0.8.0集成 提及 在我的shell中显示错误 7 def send_twilio_message(to_number, body): ----> 8 client = twilio.rest.TwilioRestClient( 9 settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN) 10
7 def send_twilio_message(to_number, body):
----> 8 client = twilio.rest.TwilioRestClient(
9 settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
10
AttributeError: 'module' object has no attribute 'TwilioRestClient'
下面的代码是为比6.0版本更旧的twilio sdk编写的
您可以尝试查找更新的教程,也可以尝试调整教程。这可能会有所帮助
最后一个选项是安装与本教程一起使用的twilio库的较旧、不受支持的版本,例如
pip install twilio==5.7
已使用解决方案更新:
twilio==6.0.0版本(当前版本)有不同的目录结构,因此影响导入结构
下面是更新后的导入结构
from django.conf import settings
import twilio
import twilio.rest
from twilio.rest import Client
def send_twilio_message(to_number, body):
client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
return client.api.account.messages.create(
body=body,
to=to_number,
from_=settings.PHONE_NUMBER
)