I am following the tutorial from https://www.twilio.com/blog/2016/09/how-to-receive-and-respond-to-a-text-message-with-python-flask-and-twilio.html.
However after starting up my flask app in one terminal window (python textapi.py), starting up ngrok in another terminal(ngrok http 5000), copying and pasting the forwarding http url into the twilio console "a message comes in" field, and then texting the number, I am left with a 404 error.
Both my flask terminal as well as my ngrok terminals register the incoming POST but both respond with a 404 error.
My flask app looks like the following:
from flask import Flask, request, redirect
import twilio
from twilio.rest import Client
from twilio.twiml.messaging_response import MessagingResponse
import pandas
import os
# Load some background data and credentials
app = Flask(__name__)
# Initiate Twilio Client
client = Client(account_sid, auth_token)
@app.route('/sms', methods=['POST'])
def sms():
number = request.form['From']
message_body = request.form['Body']
# Do stuff to get response_String
response = response_string
resp = twiml.Response()
resp.message(response)
return str(resp)
if __name__ == '__main__':
app.run()
Can someone explain where the 404 error is coming from and why it cannot locate "localhost:5000/sms"?
Also this: Flask server returns 404 on localhost:5000 w/ Twilio doesn't seem to solve my issue.
UPDATE 1: part of the issue was not having "/sms" at the end of my ngrok url that I pasted into Twilio's console.
Now I'm having an error that twiml has no attribute Response.
