2010-05-19 118 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