Django | Twilio 发送短信

3

我正在使用Twilio作为移动验证机制,但我之前没有使用过Twilio。看了一下PHP示例代码后,我在我的代码中使用了这个,但显然它给了我一个400 Bad request HTTP错误。以下是代码:

    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)

verNumber 是随机生成的,接收者的号码在 Twilio 中得到验证。

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

Error 400 The source 'From' phone number is required to send an SMS

这是什么意思?
谢谢。
2个回答

9

从Python库中的一些Twilio示例观察,我注意到包含有效负载的字典采用MixedCase而你使用了UPPERCASE。

错误可能很直接,而不是...

d = {
    'TO' : '*** *** ****',
    'FROM' : '415-555-1212',
    'BODY' : 'Hello user, please verify your device using this code %s' % verNumber
}

尝试

d = {
    'To' : '*** *** ****',
    'From' : '415-555-1212',
    'Body' : 'Hello user, please verify your device using this code %s' % verNumber
}

短信快速入门(文档中)支持这个想法。希望这可以帮到您。

3
好的,Jamie 抓得好!我可以给你寄一件 Twilio 的 T 恤吗?如果可以,请发送电子邮件至 jsheehan@twilio.com,告诉我你的地址和衬衫尺码。 - John Sheehan
+John,我能拿到一件Twilio的T恤吗?! :) - Gezim

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接