Twilio is not sending any SMS [help needed]

332 views
Skip to first unread message

shasa...@kordit.com

unread,
Sep 14, 2016, 2:50:39 AM9/14/16
to rapidpro-dev
Hi,

I have integrated my Twilio account into the RapidPro but after I tried "Start Flow", I'm not seeing any SMS being sent out (no credit being used) or received (on my handset end).

I logged into Twilio and seeing a bunch of the following,



Request Inspector

POST
2016-09-13 20:42:55 UTC
500
Request
Response
Headers
This is an error 500. Please contact you administrator.















And I could only see the following on my server side,

[14/Sep/2016 06:10:59] "POST /handlers/twilio/ HTTP/1.1" 500 56

Any idea what's happening here?

Thanks!

evan wheeler

unread,
Sep 14, 2016, 2:59:34 AM9/14/16
to shasa...@kordit.com, rapidpro-dev

Unless you own domain.com, then you need to configure with your own domain for your own rapidpro deployment.

shasa...@kordit.com

unread,
Sep 14, 2016, 3:02:02 AM9/14/16
to rapidpro-dev, shasa...@kordit.com
Hello, the domain address is an actual working domain, I have only changed it for the posting purpose.

Any idea?

shasa...@kordit.com

unread,
Sep 14, 2016, 4:05:14 AM9/14/16
to rapidpro-dev, shasa...@kordit.com
It seems that in Twilio, the Messaging portion is configured to do POST to the following URL,


But the above URL is not accessible when I access it directly.

Any idea?

Eric Newcomer

unread,
Sep 14, 2016, 7:34:09 AM9/14/16
to rapidpro-dev, shasa...@kordit.com
Looks like it's returning a 500. I'd use a tool like ngrok or something similar to sit in between and inspect the 500 error being returned to twilio.

Eric

--
You received this message because you are subscribed to the Google Groups "rapidpro-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rapidpro-dev...@googlegroups.com.
To post to this group, send email to rapidp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rapidpro-dev/f995f3f9-b866-41ab-8d8e-d82fc67fe178%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

Eric Newcomer

unread,
Sep 14, 2016, 10:21:38 AM9/14/16
to shasa...@kordit.com, rapidpro-dev
ngrok is a tool that allows you to create a local tunnel. You should start it on the same box that you are trying to debug. Then change your Twilio endpoints to go to your ngrok doman (though the path should remain the same). You will want to make sure your settings file reflects your ngrok domain as well.

Then once Twilio hits that ngrok service it'll get forwarded to your server. However, since ngrok sits in the middle it will allow you to easily inspect but requests and responses between your server and Twilio.

There are certainly other ways to do it, but ngrok is one my favorite tools for debugging things on a development server.

Eric



On Wed, Sep 14, 2016 at 9:18 AM <shasa...@kordit.com> wrote:
Hi Eric,

I'm not really familiar with ngrok but I have tried downloading it.

Would you mind elaborating a bit more on how to use ngrok to sniff the error 500 returned?

Thanks!

shasa...@kordit.com

unread,
Sep 14, 2016, 10:26:23 AM9/14/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

I have tried to setup ngrok on my server, I could see the following, but when I tried accessing the ngrok domain, I got a 502 bad gateway instead of my RapidPro page.

ngrok by @inconshreveable                                                                                                     (Ctrl+C to quit)

Session Status                online
Version                       2.1.14
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://0d742775.ngrok.io -> localhost:8000
Forwarding                    https://0d742775.ngrok.io -> localhost:8000

Connections                   ttl     opn     rt1     rt5     p50     p90
                              6       0       0.01    0.01    0.00    0.00

HTTP Requests
-------------

GET /favicon.ico
GET /


Even though, my RapidPro is running correctly on port 8000,

tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN      6632/python

Could you kindly advise?

Thanks!

On Wednesday, September 14, 2016 at 7:34:09 PM UTC+8, Eric Newcomer wrote:

Eric Newcomer

unread,
Sep 14, 2016, 10:36:44 AM9/14/16
to shasa...@kordit.com, rapidpro-dev
Hard to help with that from this end. Maybe look at ALLOWED_HOSTS and also double check your hostname is configured to the ngrok domain.

shasa...@kordit.com

unread,
Sep 14, 2016, 10:54:19 AM9/14/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

The ALLOWED_HOST was already pointing to [ * ] and I have tried changing the HOSTNAME and TEMBA_HOST parameters in settings.py to 'ngrok.io' but I was still getting the 502 bad gateway.

Does the ngrok screen look correct?

Thanks!

Eric Newcomer

unread,
Sep 14, 2016, 10:58:52 AM9/14/16
to shasa...@kordit.com, rapidpro-dev
You should include the subdomain when configuring your ngrok host, though I wouldn't necessarily expect that to cause a problem at this point. Not entirely sure why you are seeing that bad gateway. That means that ngrok is not able to forward to your local server for some reason. Usually it's because you're pointing to the wrong port or something of that nature.


shasa...@kordit.com

unread,
Sep 15, 2016, 11:19:53 AM9/15/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

I am now able to setup the ngrok to sit between the server and Twilio.

I have also point the Twilio to the custom ngrok url.

I can see the error 500 in the ngrok web interface.

Which section should I be looking at?

Thanks!

shasa...@kordit.com

unread,
Sep 15, 2016, 11:27:36 AM9/15/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

I'm getting this on the Twilio side when I tried sending a new SMS to the Twilio's number (to Trigger),

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
            <meta name="robots" content="NONE,NOARCHIVE">
                <title>ValidationError at /handlers/twilio/</title>
                <style type="text/css">
    html * { padding:0; margin:0; }
    body * { padding:10px 20px; }
    body * * { padding:0; }
    body { font:small sans-serif; }
    body>div { border-bottom:1px solid #ddd; }
    h1 { font-weight:normal; }
    h2 { margin-bottom:.8em; }
    h2 span { font-size:80%; color:#666; font-weight:normal; }
    h3 { margin:1em 0 .5em 0; }
    h4 { margin:0 0 .5em 0; font-weight: normal; }
    code, pre { font-size: 100%; white-space: pre-wrap; }
    table { border:1px solid #ccc; border-collapse: collapse; width:100%; background:white; }
    tbody td, tbody th { vertical-align:top; padding:2px 3px; }
    thead th {
      padding:1px 6px 1px 3px; background:#fefefe; text-align:left;
      font-weight:normal; font-size:11px; border:1px solid #ddd;
    }
    tbody th { width:12em; text-align:right; color:#666; padding-right:.5em; }
    table.vars { margin:5px 0 2px 40px; }
    table.vars td, table.req td { font-family:monospace; }
    table td.code { width:100%; }
    table td.code pre { overflow:hidden; }
    table.source th { color:#666; }
    table.source td { font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
    ul.traceback { list-style-type:none; color: #222; }
    ul.traceback li.frame { padding-bottom:1em; color:#666; }
    ul.traceback li.user { background-color:#e0e0e0; color:#000 }
    div.context { padding:10px 0; overflow:hidden; }
    div.context ol { padding-left:30px; margin:0 10px; list-style-position: inside; }
    div.context ol li { font-family:monospace; white-space:pre; color:#777; cursor:pointer; }
    div.context ol li pre { display:inline; }
    div.context ol.context-line li { color:#505050; background-color:#dfdfdf; }
    div.context ol.context-line li span { position:absolute; right:32px; }
    .user div.context ol.context-line li { background-color:#bbb; color:#000; }
    .user div.context ol li { color:#666; }
    div.commands { margin-left: 40px; }
    div.commands a { color:#555; text-decoration:none; }
    .user div.commands a { color: black; }
    #summary { background: #ffc; }
    #summary h2 { font-weight: normal; color: #666; }
    #explanation { background:#eee; }
    #template, #template-not-exist { background:#f6f6f6; }
    #template-not-exist ul { margin: 0 0 0 20px; }
    #unicode-hint { background:#eee; }
    #traceback { background:#eee; }
    #requestinfo { background:#f6f6f6; padding-left:120px; }
    #summary table { border:none; background:transparent; }
    #requestinfo h2, #requestinfo h3 { position:relative; margin-left:-100px; }
    #requestinfo h3 { margin-bottom:-1em; }
    .error { background: #ffc; }
    .specific { color:#cc3300; font-weight:bold; }
    h2 span.commands { font-size:.7em;}
    span.commands a:link {color:#5E5694;}
    pre.exception_value { font-family: sans-serif; color: #666; font-size: 1.5em; margin: 10px 0 10px 0; }
  </style>
                <script type="text/javascript">
  //
                    <!--
    function getElementsByClassName(oElm, strTagName, strClassName){
        // Written by Jonathan Snook, http://www.snook.ca/jon; Add-ons by Robert Nyman, http://www.robertnyman.com
        var arrElements = (strTagName == "*" && document.all)? document.all :
        oElm.getElementsByTagName(strTagName);
        var arrReturnElements = new Array();
        strClassName = strClassName.replace(/\-/g, "\-");
        var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
        var oElement;
        for(var i=0; i<arrElements.length; i++){
            oElement = arrElements[i];
            if(oRegExp.test(oElement.className)){
                arrReturnElements.push(oElement);
            }
        }
        return (arrReturnElements)
    }
    function hideAll(elems) {
      for (var e = 0; e < elems.length; e++) {
        elems

I tried to run a flow and didn't get any SMS on the handset too (I could see that 1 credit was used when I started the flow).

Any idea what the above means?

Thanks!

Eric Newcomer

unread,
Sep 15, 2016, 3:46:29 PM9/15/16
to shasa...@kordit.com, rapidpro-dev
That's the raw HTML, which for django servers running in debug mode (which looks like you are), you should see a stack trace embedded further down to give you a clue.

From the looks of the title ValidationError at /handlers/twilio/I'm willing to bet you have a validation error :)

shasa...@kordit.com

unread,
Sep 15, 2016, 9:13:41 PM9/15/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

What does that mean?

Could you elaborate more on the validationerror?

Am I using the correct url ("domain.com/handlers/twilio") to point the Twilio to?

Thanks!

Eric Newcomer

unread,
Sep 15, 2016, 9:33:42 PM9/15/16
to rapidpro-dev, shasa...@kordit.com
Rapidpro configures your twilio account for you, so not likely that's the issue. You should look at the full stack trace on that page in your ngrok view. I can only see the title you pasted but you should have a stack trace further down there showing exactly where in the code to look to figure out what your problem is.

shasa...@kordit.com

unread,
Sep 15, 2016, 9:52:21 PM9/15/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

Would it help if I provide the full raw capture from the ngrok?


I'm having some difficulties determining which portion in the raw captures that could give some hints or clues about the issue.

Thanks!

Eric Newcomer

unread,
Sep 15, 2016, 11:26:49 PM9/15/16
to shasa...@kordit.com, rapidpro-dev
Your problem is at:
/root/rapidpro-master/temba/channels/handlers.py in post, line 152

Looking at that code you see:
if not validator.validate(url, request.POST, signature):
  # raise an exception that things weren't properly signed
  raise ValidationError("Invalid request signature")


You can read about how Twilio validates request signatures here:

Something is awry with your configuration, hopefully that points you in the right direction.

Eric

shasa...@kordit.com

unread,
Sep 22, 2016, 2:36:56 AM9/22/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

I'm still unable to figure out the validationError that I was facing last week.

I tried to setup a fresh clean install of RapidPro and now I'm getting a RunTime error instead.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
            <meta name="robots" content="NONE,NOARCHIVE">
                <title>RuntimeError at /handlers/twilio</title>
                <style type="text/css">

Any idea what this is?

Thanks!

Eric Newcomer

unread,
Sep 22, 2016, 10:08:11 AM9/22/16
to shasa...@kordit.com, rapidpro-dev
Can you tell me what the actual runtime error is? There should be a complete stack included further down that page. It might help you to save the raw error html as a file and open that in a browser instead.

shasa...@kordit.com

unread,
Oct 16, 2016, 9:04:55 PM10/16/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

Is the URL correct here?

I put my "rapidprodomain.com/handlers/twilio" in my twilio settings.

I'm still trying to figure out what the issue here is, the validationError didn't point me anywhere.

Any clue?

Which part of the ngrok view do we need to help us debug this more?

Thanks!

shasa...@kordit.com

unread,
Oct 17, 2016, 3:45:02 AM10/17/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

I have tried what you suggested last time and saved all the Raw content and opened it in an html format.

I still couldn't seem to figure out what the issue that caused the validationError here.

Could you kindly help and take a look please?

Appreciate it.

Thanks a lot!
validationError.html

Eric Newcomer

unread,
Oct 17, 2016, 10:30:08 AM10/17/16
to shasa...@kordit.com, rapidpro-dev
My suspicion would be that the hostname for your server does not match how Twilio is calling to you. I would recommend putting in a pdb to step through the validation process and inspect everything that is being used for the signature construction. You definitely has some misconfiguration there.

Eric

shasa...@kordit.com

unread,
Oct 17, 2016, 10:52:35 AM10/17/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

Do you mind elaborating more?

What other configuration do we need other than the standard ones?

I tried running the server on settings.py.dev configuration file but it returned the same error.

Thanks!

Eric Newcomer

unread,
Oct 17, 2016, 11:20:06 AM10/17/16
to shasa...@kordit.com, rapidpro-dev
You need to check your hostname for your server and compare it with the Twilio app in your Twilio account. My initial guess is those don't match up. If that's not it, you need to look at all the components used to build that validation signature and inspect that using pdb.

Looking at your stack trace, putting a pdb before there, would make the most sense.
/root/rapidpro-master/temba/channels/handlers.py in post, line 152

If you've never used pdb, you can read up on that here:

Hope that helps,

Eric

shasa...@kordit.com

unread,
Oct 17, 2016, 11:23:33 AM10/17/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

Thanks for your quick response, it seems that it was the hostname.

Once I changed the server's hostname to match with the one in the settings.py, I am no longer getting the error 500.

I can see the 201 response from /handlers/twilio.

But for some reason I am not getting any SMS response.

This is the only thing I am getting on the log, something like a FAKED SEND.

M[000001844] Processing - Subscribe 123
FAKED SEND for [1848] - Invalid code.
[0.89] triggers for 1844
M[000001844] 0000.891 s - Subscribe 123
[17/Oct/2016 15:15:59] "POST /handlers/twilio/ HTTP/1.1" 201 0

Any clue why this is happening?

Thanks!

Eric Newcomer

unread,
Oct 17, 2016, 11:40:15 AM10/17/16
to shasa...@kordit.com, rapidpro-dev
You are probably running in development mode. There's a config file settings for SEND_MESSAGES which causes them to be faked during development.

shasa...@kordit.com

unread,
Oct 17, 2016, 11:54:20 AM10/17/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

Yes it seems that after I enable that parameter, it's now sending the real SMS instead.

But for some reason, the RapidPro server is responding back with incorrect responses.

Every SMS that I sent, I could see that the server is handling old SMS that I was sending previously (but no responses previously).

In this case the SMS that I send will not get the correct response as the server is sending out responses to the older SMS that I sent earlier.

Is there something like a queue that I need to flush?

Thanks!
:none; }
    .user div<span style="color

shasa...@kordit.com

unread,
Oct 17, 2016, 11:42:38 PM10/17/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

I have managed to resolve the issue.

The issue seemed to be the queue in redis and after flushing the queue it all went back to normal.

Is there anyway we could implement the BRANDING portion into the development settings.py?

Is there any particular section that we need to copy into the dev settings.py to make the application reads the BRANDING options?

Thanks!

shasa...@kordit.com

unread,
Nov 10, 2016, 9:17:15 AM11/10/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

I tried enabling SSL on my rapidpro-dev server but once I enable the SSL, the SMS stopped working.

I got the ValidationError that I got a while back which was caused by the hostname of the server vs hostname in the settings.py mismatch.

Now that the protocol has changed from HTTP to HTTPS, what could cause the server to return the same ValidationError again?

Is there a specific hostname on the server or settings.py that I need to enable in order for me to resolve the issue?

Appreciate your help.

Thanks!

shasa...@kordit.com

unread,
Nov 11, 2016, 3:20:28 AM11/11/16
to rapidpro-dev, shasa...@kordit.com
Anyone? 

shasa...@kordit.com

unread,
Nov 11, 2016, 3:21:39 AM11/11/16
to rapidpro-dev, shasa...@kordit.com
Once the SSL is enabled, the IVR seems to work but SMS stopped working and still returning the same ValidationError.

Previously this error message was caused by the hostname mismatch but I haven't changed any hostname configuration on the RapidPro side.

Anyone experiencing the same?

Appreciate, some help here. :)

Eric Newcomer

unread,
Nov 11, 2016, 5:29:44 AM11/11/16
to shasa...@kordit.com, rapidpro-dev
I would double check the endpoints for SMS messaging in your Twilio configuration. Make sure those point to your https endpoint.

Eric

--
You received this message because you are subscribed to the Google Groups "rapidpro-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rapidpro-dev+unsubscribe@googlegroups.com.

To post to this group, send email to rapidp...@googlegroups.com.

shasa...@kordit.com

unread,
Nov 11, 2016, 8:19:53 AM11/11/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

Yes the Twilio side is pointing to https instead of http now but it's still returning the ValidationError now.

Would there be any other configuration that's relevant to SSL?

Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to rapidpro-dev...@googlegroups.com.

To post to this group, send email to rapidp...@googlegroups.com.

Eric Newcomer

unread,
Nov 11, 2016, 8:50:03 AM11/11/16
to shasa...@kordit.com, rapidpro-dev
I would put a pdb in your server at the point of the validation and compare what is being evaluated at that point to learn more.

To unsubscribe from this group and stop receiving emails from it, send an email to rapidpro-dev+unsubscribe@googlegroups.com.

To post to this group, send email to rapidp...@googlegroups.com.

shasa...@kordit.com

unread,
Nov 11, 2016, 8:57:32 AM11/11/16
to rapidpro-dev, shasa...@kordit.com
Hi Eric,

What's a pdb? Something like ngrok that you mentioned and I used previously?

Thanks!
Reply all
Reply to author
Forward
0 new messages