Skip to content Skip to sidebar Skip to footer

Getting A View Does Not Return A Valid Response Error Message On My Flask Chatbot

Trying to create a whatsapp bot on Twilio that limits the number of requests a user can make within a 24 hour period. However, when I send through a request I get this error messag

Solution 1:

The problem is that you are not returning a response which flask thinks as a valid response. You can read more about responses in flask here.

So in your case add a return after all of your ifs under if request_check(user=cleaned_number): in bot() method. Also you should not return None. I think you are looking to return a json (just an advice).

For example:

@app.route('/bot', methods=['POST'])
def bot():
    incoming_msg = request.values.get('Body', '').lower()
    resp = MessagingResponse()
    #extract phone number from ngrok
    number = request.values.get('From', '')
    #remove non numerical values
    cleaned_number = re.sub('[^0-9]', '', number)
    msg = resp.message()
    #createnewuser
    add_user(user=cleaned_number)
    responded =False
    if request_check(user=cleaned_number):
        if incoming_msg =='help':
            output ='Introduction text.'
            msg.body(output)
            responded =Truereturn "My Message"

Post a Comment for "Getting A View Does Not Return A Valid Response Error Message On My Flask Chatbot"