SITUATION: So i followed a 3 video short tutorial by sentdex on youtube named "Alexa Skills w/ Python and Flask-Ask" parts 1, 2 and 3. Basically when i run this skill, alexa will read me the first 10 headlines from reddit.com/ r/ worldnews (cant give more than 8 URL for this post unfortunately).
ERROR I'M HAVING: I followed all steps and i keep getting this error when i test it out in the Amazon Alexa development site saying: "There was a problem with the requested skill's response". One issue i have is that the alexa development console has been updated a few months ago and is completely different so i have no clue if i did something wrong or not. All the youtube videos i have seen are on the old version which has a different way of doing things. I'm going to outline exactly what i have done and hopefully u guys could point what i did wrong.
WHAT I TRIED: I will also like to mention that i have tried replacing the contents of the get_headlines function with a return command that returns a string for alexa to say like: "it works". But i got the same error message on the development site. So I'm guessing that my code is fine but i might have configured the setting in my alexa dev account wrong. Below, i have included pictures of every step i have done for this simple program.
EXACTLY STEPS I HAVE TAKEN:
1) I have installed flask, flask-ask, and unidecode with the pip installer
2) I downloaded ngrok to host my site
3) CODE: This is the code i have ran (took out my reddit username and password for obvious reasons). It has no errors and the homepage runs fine. So i guess there is no issue with the code itself.
from flask import Flask, render_template
from flask_ask import Ask, statement, question, session
import json
import requests
import time
import unidecode
app = Flask(__name__)
ask = Ask(app, "/big_reader")
def get_headlines(): # DESCRIPTION: get_headlines function will grab the headlines from redit and then its going "stringify" all the headlines together
# 1) LOG INTO REDDIT API
user_pass_dict = {
'user': 'ENTER_YOUR_REDDIT_USERNAME',#'ENTER_YOUR_USERNAME',
'passwd': 'YOUR_REDDIT_PASSWORD',
'api_type': 'json'
}
# Requesting a session from api
sess = requests.Session()
sess.headers.update( {'User-Agent': 'I am testing Alexa Here'} )
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 = []
for listing in data['data']['children']:
titles.append( unidecode.unidecode(listing['data']['title']) )
titles = '...'.join([i for i in titles])
return titles
################################# ALEXA STUFF ###################################################################################################
@app.route('/')
def homepage():
return "This is the Homepage"
# A) ALEXA ASKS SOMETHING:
@ask.launch
def start_skill():
welcome_message = 'Sup, You want some news?'
return question(welcome_message)
# B) MY RESPONSE:
@ask.intent("YesIntent")
def share_headlines():
headlines = get_headlines()
headline_msg = 'The current world news headlines are {}'.format(headlines) #string format the headlines?
return statement(headline_msg)
@ask.intent("NoIntent")
def no_intent():
bye_text = 'bye'
return statement(bye_text)
# RUN
if __name__ == '__main__':
app.run(debug=True)
4) PICTURES OF HOW I SET UP MY ALEXA SKILL: Here are 10 images that shows exactly what my alexa developer web page looks like
https://ibb.co/ZdMdgGF <-- my yes intent
https://ibb.co/4N4JygL <-- the JSON editor screen of my skill
https://ibb.co/c2HDw8h <-- What my interface screen looks like
https://ibb.co/BP6ck2L <--how my ngrok looks after running: ngrok http 5000
https://ibb.co/3k5J7wZ <--copying my ngrok https address to alexa endpoint.
https://i.sstatic.net/q9X2E.jpg <--i even tried adding "/big_reader" at the end of it.
https://ibb.co/3s3tVQH <--the build was successful
https://ibb.co/wgF7GQ4 <--I tried to start the big reader skill and got error
I had the same problem.
I fixed it by downgrading cryptography to 2.1.4 with pip install cryptography==2.1.4