使用 Twilio 发送短信时出现 TwilioRestException

问题描述 投票:0回答:2
import os
from twilio.rest import Client

account_sid = 'my_account_sid' 
auth_token = 'my_auth_token' 

client = Client(account_sid, auth_token) 

def send_sms(user_code , phone_number):
    message = client.messages.create(
        body= f'Hi your verification code is {user_code}',
        from_ = '+14158557747',
        to = f'{phone_number}')

# 电话号码采用国际格式,如下所示 +9779845000001

我在运行服务器时收到以下错误日志..

Request Method: GET
Request URL:    http://127.0.0.1:8000/verify/
Django Version: 3.1.6
Exception Type: TwilioRestException
Exception Value:    
[31m[49mHTTP Error[0m [37m[49mYour request was:[0m

[36m[49mPOST /Accounts/AC3c6c0502535317b9bb95efd43c6296d1/Messages.json[0m

[37m[49mTwilio returned the following information:[0m

[34m[49mUnable to create record: Authenticate[0m

[37m[49mMore information may be available here:[0m

[34m[49mhttps://www.twilio.com/docs/errors/20003[0m

任何帮助将不胜感激。

rest exception twilio twilio-api
2个回答
0
投票

只需从 Twilio 控制台查看并输入帐户 Sid。当复制并粘贴时,此帐户的 sid 将会更改。您可以复制并粘贴令牌。 如果是试用账户,请确保“收件人”号码经过验证。


0
投票

我也有类似的问题,原因是我的账户余额为负。因此,升级您的信用或创建一个新帐户。

https://www.twilio.com/docs/iot/kore-acquisition/link-your-twilio-kore-accounts

© www.soinside.com 2019 - 2024. All rights reserved.