如何迭代Twilio SMS的列表?

问题描述 投票:0回答:1

我正在为Twilio开发一个python应用程序。我需要将短信发送到多个号码。

作为测试,我将两个数字放入列表中进行迭代。我遇到的问题是,在我的迭代中只查看第一个数字而不是下一个数字。我通过设置10秒的暂停并在我的号码上获得两次相同的文本来发现这一点。

我错误的是迭代没有迭代列表中的下一个值?

码:

from twilio.rest import Client
import time

# Your Account SID from twilio.com/console
account_sid = "xxxx"
# Your Auth Token from twilio.com/console
auth_token  = "xxxx"

client = Client(account_sid, auth_token)


lst = ["+11111111111","+22222222222"]

for i in lst:
    message = client.messages.create(
            to=lst, 
            from_="+1234567890",
            body="Hello from Python!")
    time.sleep(10)
    print(message.sid)
python sms twilio
1个回答
4
投票

在创建消息对象时,在for循环中用to=lst替换to=i,就像这样

for i in lst:
    message = client.messages.create(
            to=i, 
            from_="+1234567890",
            body="Hello from Python!")
    time.sleep(10)
    print(message.sid)
© www.soinside.com 2019 - 2024. All rights reserved.