Django | twilio send SMS

I use twilio as a mobile validation mechanism, I have no previous experience using twilio, but looking at a sample PHP code, I used it in my code, but apparently it gave me an HTTP error 400 Bad request. Here is 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 randomly generated, and the receiver number is checked 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 it mean?

Thank.

+3
source share
2 answers

After looking at some of the twilio examples from the python libraries, I notice that dictionaries containing the payload are printed in MixedCase, while you used TOP.

The error can be quite straightforward rather than

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

to try

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

SMS Quickstart ( ) .

, .

+9

Source: https://habr.com/ru/post/1746126/


All Articles