Issue
I am trying a flash application below is my code that i am following from tutorial
from flask import Flask, request
import requests
from twilio.twiml.messaging_response import MessagingResponse
app = (__name__)
@app.route('/mybot',methods=['POST'])
def mybot():
incoming_message = request.values.get('Body','').lower()
resp = MessagingResponse()
msg = resp.message()
responded = False
if 'hi' in incoming_message:
msg.body('Hello, iam luja')
responded = True
if 'quotes' in incoming_message:
r = request.get('https://api.quotable.io/random')
if r.status_code == 200:
data = r.json()
quote = f'{data["content"]}({data["author"]})'
else:
quote = 'not able to retrieve'
msg.body(quote)
responded = True
if 'who are you' in incoming_message:
msg.body('Hi i am Bot')
responded = True
if not responded:
msg.body('not able to return the msg')
return str(resp)
if __name__ == '__main__':
app.run()
I have installed all required dependancies. However when I run the code I get the above error, how can i resolve this error?
Solution
You need to change:
app = (__name__)
to:
app = Flask(__name__)
Otherwise app is assigned __name__
which is a str
, and as the error message says it does not have a route
attribute. In the latter case, app is assigned an instance of Flask()
which does have the required route
attribute.
Answered By - Allan Wind
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.