Forums

Twilio 11200 Error when trying to access PythonAnywhere - HTTP retreival failure

I occasionally get this error and can't figure out why


From Twilio: "There was a failure attempting to retrieve the contents of this URL. An 11200 error is an indicator of a connection failure between Twilio and your service. When Twilio requests a page from your server, we wait a maximum of 15 seconds for a response. A connection failure will occur if no response is returned in that time."


When I looked at the error more closely it said An attempt to retrieve content from website returned the HTTP status code 403.

I had no errors on the PythonAnywhere logs. This happens every couple days and my code all of sudden won't run. Then If I reload or wait for a while, it will work again.

Any help on this would be appreciated!

how do you do the twillio auth? is it just only run when your website is reloaded?

Actually now that you ask, it is right before the first function. Should I be calling this under the first function?


# Find these values at https://twilio.com/user/account
account_sid = "ID NUMBER"
auth_token = "AUTH TOKEN"
client = TwilioRestClient(account_sid, auth_token)
#---------------


app = Flask(__name__)

@app.route("/", methods=['GET', 'POST'])

def dispatch():

    global c
    global conn
    conn = MySQLdb.connect("mysql.server", *username*, *Name*, *database*)
    c = conn.cursor()

Maybe if twilio times out / logs out the client every couple days, then you would get this error?

I'm getting the same error occasionally and this is frustrating, Auth doesn't seem to be the issue for me (tried it inside the function as well but it doesn't fix the problem.

Anyone else has an idea of what could it be?

From twilio's website :

An 11200 error is an indicator of a connection failure between Twilio and your service. When Twilio requests a page from your server, we wait a maximum of 15 seconds for a response. A connection failure will occur if no response is returned in that time. There are many reasons a connection timeout can occur; common causes are long running database queries or outside processes and calls to external systems taking a long time to return. It may be possible your application experienced one of these issues. If you are encountering this error only intermittently, it is possible that your web server was temporarily unavailable or experiencing a network outage. https://www.twilio.com/console/runtime/debugger/NOa8ddb129977e1dfaf78f85d8c2046f71

what does the code do in your endpoint that twilio hits?

It's a chatbot in a flask app, using twilio SMS as input, retrieving answer using api.ai and then sending the answer using twilio (basically this) with few tweaks, like saving the result in a mySql db.

do you know what version of the twilio client library you're running? can you try upgrading it?

So I did upgrade my programs since I was running an older version of twilio; now I'm using the latest built.

Still getting the error on occasions though. I'm using my pythonanywhere app as a twilio webhook and I can set in twilio another webhook when primary handler fails which I redirect to the same pythonanywhere app.

The problem doesn't seem to be in my program because when twilio fails to retrieve content on first try, it usually succeeds on second try via the secondary webhook. There are no errors in my logs, only thing I noticed is in the access log :

[04/Nov/2017:04:27:51] "POST / HTTP/1.1" 200 50 "-" "TwilioProxy/1.1" "34.207.124.84" response-time=0.390 [04/Nov/2017:04:28:00] "POST / HTTP/1.1" 200 50 "-" "TwilioProxy/1.1" "54.210.32.202" response-time=0.425 [04/Nov/2017:04:28:17] "POST / HTTP/1.1" 200 50 "-" "TwilioProxy/1.1" "54.209.65.101" response-time=0.474 [04/Nov/2017:11:35:39 "POST / HTTP/1.1" 200 50 "-" "TwilioProxy/1.1" "54.242.73.127" response-time=1.595 [05/Nov/2017:00:06:32] "POST / HTTP/1.1" 503 5 "-" "TwilioProxy/1.1" "34.229.219.100" response-time=4.869 [05/Nov/2017:00:06:35] "POST / HTTP/1.1" 200 50 "-" "TwilioProxy/1.1" "54.210.32.202" response-time=2.363 [06/Nov/2017:03:22:36] "POST / HTTP/1.1" 200 50 "-" "TwilioProxy/1.1" "34.207.124.84" response-time=1.726 [06/Nov/2017:03:22:46] "POST / HTTP/1.1" 200 50 "-" "TwilioProxy/1.1" "54.227.125.220" response-time=0.351 [09/Nov/2017:13:55:50] "POST / HTTP/1.1" 200 50 "-" "TwilioProxy/1.1" "52.90.170.52" response-time=0.597 [09/Nov/2017:13:56:04] "POST / HTTP/1.1" 200 50 "-" "TwilioProxy/1.1" "54.174.2.223" response-time=0.635 [09/Nov/2017:13:56:28] "POST / HTTP/1.1" 200 50 "-" "TwilioProxy/1.1" "34.229.95.231" response-time=0.688 [10/Nov/2017:01:09:00] "POST / HTTP/1.1" 503 5 "-" "TwilioProxy/1.1" "52.54.134.254" response-time=4.866 [10/Nov/2017:01:09:01] "POST / HTTP/1.1" 200 50 "-" "TwilioProxy/1.1" "54.173.40.131" response-time=0.931

The only time I hit the 503 error it seems I'm having a longer response time ( > 4 sec). It it still weird because in Twilio's doc, they state that they wait for a maximum of 15 seconds which I'm nowhere near :

An 11200 error is an indicator of a connection failure between Twilio and your service. When Twilio requests a page from your server, we wait a maximum of 15 seconds for a response. A connection failure will occur if no response is returned in that time.

it might be caused by one of our maintenance processes where we need to move your webapp from one server to another -- those times do look like they might match up. does twilio automatically retry?

It retries automatically once and it seems to always work on second try but I've been testing with a very limited number of hits. I was worried that when I'll test my webbapp with more users this might become an issue.

Let me give you other examples to help you see if your theory is correct :

[02/Nov/2017:00:09:28] "POST / HTTP/1.1" 503 5 "-" "TwilioProxy/1.1" "34.203.210.163" response-time=4.778 [02/Nov/2017:00:09:33] "POST / HTTP/1.1" 200 50 "-" "TwilioProxy/1.1" "184.72.90.231" response-time=4.442

[31/Oct/2017:01:54:17] "POST / HTTP/1.1" 503 5 "-" "TwilioProxy/1.1" "34.230.6.0" response-time=5.019 [31/Oct/2017:01:54:18] "POST / HTTP/1.1" 200 50 "-" "TwilioProxy/1.1" "54.152.150.211" response-time=1.042

[22/Oct/2017:19:56:53] "POST / HTTP/1.1" 503 5 "-" "TwilioProxy/1.1" "34.230.57.86" response-time=4.758 [22/Oct/2017:19:56:55] "POST / HTTP/1.1" 200 50 "-" "TwilioProxy/1.1" "54.159.161.202" response-time=2.220

that does seem like the most plausible explanation. as long as twilio systematically does a retry, the second hit should always work. we're looking into ways to get the first hit working too...