我只是在学习使用 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
在测试中输入话语“start armstrong”后的服务响应是:
There was an error calling the remote endpoint, which returned HTTP 500 :
INTERNAL SERVER ERROR
这是我的第一个 Alexa Skill。我正在尝试在 Python 上使用 Flask 和 flask-ask 来实现它。请帮忙。