Django | twilio发短信

Swi*_*tch 3 django twilio

我使用twilio作为移动验证机制,我以前没有使用twilio的经验,但看着我在我的代码中使用这个示例PHP代码,但显然它给了我一个400 Bad requestHTTP错误.这是代码:

    d = {
        'TO' : '*** *** ****',
        'FROM' : '415-555-1212',
        'BODY' : 'Hello user, please verify your device using                    this code %s' % verNumber
    }
    try:
        print account.request('/%s/Accounts/%s/SMS/Messages' % \
                            (API_VERSION, ACCOUNT_SID), 'POST', d)
    except Exception, e:
        return HttpResponse('Error %s' % e)
Run Code Online (Sandbox Code Playgroud)

verNumber 随机生成,接收者的号码在twilio中验证.

我遵循异常并发现了这个错误

Error 400 The source 'From' phone number is required to send an SMS
Run Code Online (Sandbox Code Playgroud)

这是什么意思.?

谢谢.

小智 9

看一下python库中的一些twilio示例,我注意到包含有效负载的字典在MixedCase中输入,而你使用了大写.

错误可能很简单,而不是

d = {
    'TO' : '*** *** ****',
    'FROM' : '415-555-1212',
    'BODY' : 'Hello user, please verify your device using this code %s' % verNumber
}
Run Code Online (Sandbox Code Playgroud)

尝试

d = {
    'To' : '*** *** ****',
    'From' : '415-555-1212',
    'Body' : 'Hello user, please verify your device using this code %s' % verNumber
}
Run Code Online (Sandbox Code Playgroud)

SMS快速入门(在文档中)支持这个想法.

希望这可以帮助.

  • 好抓杰米!我可以寄你Twilio的T恤吗?如果是这样,请将您的地址和衬衫尺寸通过电子邮件发送给twilio dot com的jsheehan (3认同)