I am just learning to write Alexa skills using Flask-Ask. Here is the code for flask_app.py:
from flask import Flask, render_template
from flask_ask import Ask, statement, question, session
import random
app = Flask(__name__)
ask = Ask(app, "/")
def armstrong(num):
order = len(str(num))
num_sum = 0
temp = num
while temp > 0:
digit = temp % 10
num_sum += digit ** order
temp //= 10
if num == num_sum:
return True
else:
return False
@ask.launch
def new_game():
welcome_msg = render_template('welcome')
return statement(welcome_msg)
@ask.intent("AnswerIntent", convert = {'first': int} )
def answer(first):
if armstrong(int(first)):
msg = render_template('win')
else:
msg = render_template('lose')
return statement(msg)
if __name__ == '__main__':
app.run()
This is the code for intents JSON file:
{
"intents": [{
"intent": "AnswerIntent",
"slots": [{
"name": "number",
"type": "AMAZON.NUMBER"
}]
}]
}
These are my sample Utterances:
AnswerIntent {number}
AnswerIntent My number is {number}
AnswerIntent Is {number} an armstrong number
But the error on my command line is:
[2017-07-09 15:37:07,543] ERROR in app: Exception on / [POST]
Traceback (most recent call last):
File "C:\Users\Sayantan Das\AppData\Local\Programs\Python\Python36\lib\site- packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\Sayantan Das\AppData\Local\Programs\Python\Python36\lib\site- packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\Sayantan Das\AppData\Local\Programs\Python\Python36\lib\site- packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Sayantan Das\AppData\Local\Programs\Python\Python36\lib\site- packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Users\Sayantan Das\AppData\Local\Programs\Python\Python36\lib\site- packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\Sayantan Das\AppData\Local\Programs\Python\Python36\lib\site- packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\Sayantan Das\AppData\Local\Programs\Python\Python36\lib\site- packages\flask_ask\core.py", line 571, in _flask_view_func
ask_payload = self._alexa_request(verify=self.ask_verify_requests)
File "C:\Users\Sayantan Das\AppData\Local\Programs\Python\Python36\lib\site- packages\flask_ask\core.py", line 533, in _alexa_request
timestamp = aniso8601.parse_datetime(alexa_request_payload['request']['timestamp'])
File "C:\Users\Sayantan Das\AppData\Local\Programs\Python\Python36\lib\site- packages\aniso8601\time.py", line 120, in parse_datetime
isodatestr, isotimestr = isodatetimestr.split(delimiter)
AttributeError: 'int' object has no attribute 'split'
127.0.0.1 - - [09/Jul/2017 15:37:07] "POST / HTTP/1.1" 500 -
ngrok shows the following error:
HTTP Requests
-------------
POST / 500 INTERNAL SERVER ERROR
And the Service Response after Entering Utterance 'start armstrong' at Testing is:
There was an error calling the remote endpoint, which returned HTTP 500 :
INTERNAL SERVER ERROR
This is my First Alexa Skill.I am trying to implement it using Flask and flask-ask on Python. Pls help.