zen_of_python
zen_of_python

Reputation: 167

404 Error - Twilio Python Quickstart

I'm following the Twilio Python Quickstart guide, and I'm having some trouble getting the SMS-response part working.

Whenever I send a message to my Twilio number, my ngrok log logs it under HTTP Requests, but notes a 404 NOT FOUND error.

I have the following code in my "run.py" file:

# /usr/bin/env python
# Download the twilio-python library from twilio.com/docs/libraries/python
from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse

app = Flask(__name__)

@app.route("/sms", methods=['GET', 'POST'])
def sms_ahoy_reply():
    """Respond to incoming messages with a friendly SMS."""
    # Start our response
    resp = MessagingResponse()

    # Add a message
    resp.message("Ahoy! Thanks so much for your message.")

    return str(resp)

if __name__ == "__main__":
    app.run(debug=True)

I have configured my Twilio number with the correct forwarding ngrok web address.

Any ideas on what I may be doing wrong?

Thanks!

Upvotes: 2

Views: 912

Answers (1)

akshayKhanapuri
akshayKhanapuri

Reputation: 287

I understand that the question is quite old and you must have already fixed the problem, but still I'm posting my understanding so that it may help any other learners like me in the future.

So basically 404 not found is a client side error and the following may be the possible causes:

++ The endpoint doesnt exist ++ The endpoint exists but the resource doesnt

From the code pasted above, I am assuming that you are trying to access the /sms endpoint

So my best guess would be to check the webhook url configured for messaging for your twilio number. We will have to make sure that the ngrok address is followed by '/sms'

that is: http://ngrok_public_address/sms

Let me know if you used another approach to solve the issue

Upvotes: 2

Related Questions