我制作了本教程: https://pythonprogramming.net/intro-alexa-skill-flask-ask-python-tutorial/
这意味着我具有与我刚刚更新的用户名和密码完全相同的代码。我已经按照步骤进行了所有操作,已经进行了3次,并且每次都会出现错误。 这是我的代码:
from flask import Flask
from flask_ask import Ask, statement, question, session
import json
import requests
import time
import unidecode
app = Flask(__name__)
ask = Ask(app, "/reddit_reader")
def get_headlines():
user_pass_dict = {'user': '***',
'passwd': '****',
'api_type': 'json'}
sess = requests.Session()
sess.headers.update({'User-Agent': 'I am testing Alexa: Sentdex'})
sess.post('https://www.reddit.com/api/login', data = user_pass_dict)
time.sleep(1)
url = 'https://reddit.com/r/worldnews/.json?limit=10'
html = sess.get(url)
data = json.loads(html.content.decode('utf-8'))
titles = [unidecode.unidecode(listing['data']['title']) for listing in data['data']['children']]
titles = '... '.join([i for i in titles])
return titles
@app.route('/')
def homepage():
return "How is it going mate?"
@ask.launch
def start_skill():
welcome_message = 'Hello there, would you like the news?'
return question(welcome_message)
@ask.intent("YesIntent")
def share_headlines():
headlines = get_headlines()
headline_msg = 'The current world news headlines are {}'.format(headlines)
return statement(headline_msg)
@ask.intent("NoIntent")
def no_intent():
bye_text = 'I am not sure why you asked me to run then, but okay... bye'
return statement(bye_text)
if __name__ == '__main__':
app.run(debug=True)
此外,我还启动了一个ngrok服务器。当我尝试测试我的技能时,alexa会回答我:“所请求的技能的响应有问题”,我的ngrok服务器告诉我:“ POST / reddit_reader 500内部服务器错误”我不知道我在做什么错,我已重复该教程3次。如果有人可以帮助我,那将是非常棒的。 调试功能也帮不了我