Alexa Skill使用flask-ask:HTTP 500:INTERNAL SERVER ERROR

时间:2017-07-09 10:43:17

标签: python alexa alexa-skill ngrok flask-ask

我正在学习使用Flask-Ask编写Alexa技能。  这是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()

这是意图JSON文件的代码:

{
"intents": [{
  "intent": "AnswerIntent",
        "slots": [{
              "name": "number",
             "type": "AMAZON.NUMBER"
         }]
  }]
}

这些是我的示例话语:

AnswerIntent {number}
AnswerIntent My number is {number} 
AnswerIntent Is {number} an armstrong number

但我命令行上的错误是:

[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显示以下错误:

HTTP Requests
-------------

POST /                         500 INTERNAL SERVER ERROR

进入话语后的服务响应'启动阿姆斯特朗'在测试是:

    There was an error calling the remote endpoint, which returned HTTP 500 :
    INTERNAL SERVER ERROR

这是我的第一个Alexa Skill。我正在尝试使用Flask和burn-ask在Python上实现它。 请帮助。

1 个答案:

答案 0 :(得分:0)

看起来它可能是Alexa测试工具的问题。请参阅https://github.com/johnwheeler/flask-ask/issues/152https://forums.developer.amazon.com/questions/78372/timestamp-is-sent-in-different-formats.html

我可以确认我的技能适用于Alexa管理页面的测试部分中的Echo设备和JSON选项卡。但它在echosim.io和Text选项卡中失败。