Why do I get the error AttributeError: 'module' object has no attribute 'Response' in my SMS app that interfaces with Twilio?

Viewed 4182

Also in ngrok, there appears an internal server error 500 when attempting to make a post request using twilio.

Here is the section of my code where I feel there is a problem with:

from flask import Flask, request
from twilio import twiml
import wolframalpha
import wikipedia

app = Flask(__name__)

wolf = wolframalpha.Client(wolfram_app_id)


@app.route('/', methods=['POST'])
def sms():

    message_body = request.form['Body']
    resp = twiml.Response()

    replyText = getReply(message_body) 
    resp.message('Hi\n\n' + replyText )
    return str(resp)

I have updated all latest versions of ngrok, python, twilio and Flask. I also followed all the steps to activate the virtualenv.

2 Answers

This code is been using Flask for sending message

For installing use:

* pip install flask
* pip install twilio

from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse

app = Flask(__name__)

@app.route("/sms", methods =['POST'])
def sms():
    number = request.form['From']
    message_body = request.form['Body']

    resp = MessagingResponse()
    response_message = 'Hello {}, You said:{}'.format(number, message_body)
    resp.message(response_message)

    return str(resp)

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