姜戈 | twilio 发送短信

发布于 2024-09-02 09:17:50 字数 753 浏览 1 评论 0原文

我使用 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

,这是什么意思?

谢谢。

I'm using twilio as for a mobile verification mechanism, I have no prior experience in using twilio but looking at the sample PHP code I used this one in my code but apparently it's giving me an 400 Bad request HTTP error. Here's the code:

    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 is randomly generated and the receiver's number is validated in twilio.

I follow the exception and found this error

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

What does this mean.?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无所的.畏惧 2024-09-09 09:17:50

查看 python 库中的 一些 twilio 示例,我注意到包含有效负载的字典是输入混合大小写,而您使用的是大写字母。

该错误可能非常直接,而不是

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
}

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

希望这有帮助。

Looking at some of the twilio examples from the python libraries I notice that the dictionaries containing the payload are typed in MixedCase whereas you've used UPPERCASE.

The error might be quite straight forward rather than

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

try

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

The SMS Quickstart ( in the documentation) supports this idea.

Hope this helps.

短叹 2024-09-09 09:17:50

尝试 http://bitbucket.org/vgavro/django-smsgate/ ,您可能需要为 twilio 编写后端 - 但剩下的已经为你完成了。

Try http://bitbucket.org/vgavro/django-smsgate/ , you may need to write backend for twilio - but the rest is done for you already.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文