2

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.

Naveen Vijay
  • 15,928
  • 7
  • 71
  • 92
Sayantan Das
  • 189
  • 1
  • 16

1 Answers1

0

Looks like it may be a problem with the Alexa testing tools. See https://github.com/johnwheeler/flask-ask/issues/152 and https://forums.developer.amazon.com/questions/78372/timestamp-is-sent-in-different-formats.html.

I can confirm that my skill works on an Echo device and the JSON tab in the Test section of the Alexa admin page. But it fails at echosim.io and in the Text tab.

pzzd
  • 111
  • 1
  • 7
  • The flask-ask project addressed the timestamp issue in commit #152. And echosim.io seems to be working now, too. – pzzd Jul 19 '17 at 16:58