2010-05-19 116 views
3

我正在使用twilio作为移动验证机制,我没有使用twilio的先前经验,但查看我在代码中使用这个代码的示例PHP代码,但显然它给了我一个400 Bad request HTTP错误。下面的代码:Django | twilio发送短信

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 

这是什么意思?

谢谢。

回答

9

从python库中查看some of the twilio examples我注意到包含有效内容的字典在MixedCase中键入,而您使用了大写字母。

的错误可能是相当简单的,而不是

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

好的杰米!我可以给你发Twilio的T恤吗?如果是这样,请通过电子邮件将您的地址和衬衫尺寸发送给jsheehan at twilio dot com – 2010-05-19 15:52:39

+0

+ John,我可以买Twilio T恤吗? :) – Gezim 2012-10-25 20:41:25