使用 Python SDK 通过 client.notify.services() 创建通知服务时出现 AttributeError

AttributeError when creating Notify service via client.notify.services() using the Python SDK

我正在尝试在 Twilio(Python SDK,v 6.4.3)中为与 SMS 相关的通知服务创建绑定,但它一直给我一个 AttriuteError。代码很简单:

from twilio.rest import Client
from myproj.twilio_settings import ACCNT_SID, AT, SERV_SID

client = Client(ACCNT_SID, AT)

service = client.notify.services(SERV_SID)

def bind_user_to_twilio_notify_service(user_id,phone_number):
    binding = service.bindings.create(
        identity=user_id,
        binding_type='sms',
        address=phone_number,
    )
    print(binding.sid)

错误是:

AttributeError: 'Client' object has no attribute 'notify'

尝试 service = client.notifications.v1.services(SERV_SID) 给了我

AttributeError: 'NotificationList' object has no attribute 'v1'

此处为 Twilio 开发人员布道师。

Notify is currently available in public beta and as such it is supported only by the alpha version of helper libraries. You'll need to install the alpha Python library,喜欢:

pip install twilio==6.4.3a1

那么你可以使用 client.notify.services(SERV_SID).