首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Alexa使用flask-ask的技巧: HTTP 500 :内部服务器错误

Alexa使用flask-ask的技巧: HTTP 500 :内部服务器错误
EN

Stack Overflow用户
提问于 2017-07-09 18:43:17
回答 1查看 1.2K关注 0票数 2

我只是在学习用Flask-Ask写Alexa的技巧。以下是flask_app.py的代码:

代码语言:javascript
复制
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()

这是intents JSON文件的代码:

代码语言:javascript
复制
{
"intents": [{
  "intent": "AnswerIntent",
        "slots": [{
              "name": "number",
             "type": "AMAZON.NUMBER"
         }]
  }]
}

以下是我的发言示例:

代码语言:javascript
复制
AnswerIntent {number}
AnswerIntent My number is {number} 
AnswerIntent Is {number} an armstrong number

但是我命令行上的错误是:

代码语言:javascript
复制
[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显示以下错误:

代码语言:javascript
复制
HTTP Requests
-------------

POST /                         500 INTERNAL SERVER ERROR

并且在测试时输入话语'start armstrong‘之后的服务响应是:

代码语言:javascript
复制
    There was an error calling the remote endpoint, which returned HTTP 500 :
    INTERNAL SERVER ERROR

这是我的第一个Alexa Skill.I,我正在尝试在Python上使用Flask和flask-ask实现它。请帮帮忙。

EN

回答 1

Stack Overflow用户

发布于 2017-07-10 22:31:44

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

我可以确认我的技能在Echo设备和Alexa管理页面的Test部分的JSON选项卡上有效。但它在echosim.io和Text选项卡中失败。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44995515

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档