2021年4月9日星期五

Alexa Skills Kit "Skill execution returned an exception for requestId" error

I'm very new to the Alexa Skills Kit. And I`ve been trying to make a simple music player skill on a web hosted server in https://www.pythonanywhere.com. When I try to make a request a

"SKILL_ENDPOINT_ERROR"

is captured in the device log with the following description:

"Skill execution returned an exception for requestId amzn1.echo-api.request.e08ec414-0a30-4e95-87bb-28f315c8d4eb".

This is my skill request handler code:

from ask_sdk_core.skill_builder import SkillBuilder  from ask_sdk_core.utils import is_intent_name, is_request_type  from flask import Flask  from flask_ask_sdk.skill_adapter import SkillAdapter  from ask_sdk_model.ui import SimpleCard    app = Flask(__name__)  sb = SkillBuilder()      #VARIABLES  Current_song = ""  silent_mode = False    """/////////////////////////  //  Request Handlers  //  ////////////////////////"""    #Launch request  @sb.request_handler(can_handle_func=is_request_type("LaunchRequest"))  def launch_request_handler(handler_input):        speech_text = "What do you wish to play?"        return handler_input.response_builder.speak(speech_text).set_card(          SimpleCard("Hello World", speech_text)).set_should_end_session(          False).response    #Session Ended Request  @sb.request_handler(can_handle_func=is_request_type("SessionEndedRequest"))  def session_ended_request_handler(handler_input):        return handler_input.response_builder.response    """/////////////////////////  //  ASK Intent Handlers  //  ////////////////////////"""    #Help Intent  @sb.request_handler(can_handle_func=is_intent_name("AMAZON.HelpIntent"))  def help_intent_handler(handler_input):        speech_text = "You can ask me to play something on your server!"        return handler_input.response_builder.speak(speech_text).ask(          speech_text).set_card(SimpleCard(              "Wha can I do", speech_text)).response    #Stop Skill intent  @sb.request_handler(      can_handle_func=lambda handler_input:          is_intent_name("AMAZON.CancelIntent")(handler_input) or          is_intent_name("AMAZON.StopIntent")(handler_input))  def cancel_and_stop_intent_handler(handler_input):        speech_text = "Goodbye!"        return handler_input.response_builder.speak(speech_text).set_card(          SimpleCard("Hello World", speech_text)).response    #FallBack Intent  @sb.request_handler(can_handle_func=is_intent_name("AMAZON.FallbackIntent"))  def fallback_handler(handler_input):        speech = (          "I can't help you with that.  "          "You can ask me to play music!")      reprompt = "You can ask me to play music!"      handler_input.response_builder.speak(speech).ask(reprompt)      return handler_input.response_builder.response    """/////////////////////////  //  Bot Intent Handlers  //  ////////////////////////"""    #Play Intent  @sb.request_handler(can_handle_func=is_intent_name("PlayIntent"))  def Play_intent_handler(handler_input):      song_value = handler_input.request_envelope.request.intent.slots["music"].value        if song_value:              speak_output = "Now playing {} on our server.".format(song_value)              Current_song = song_value      else:              speak_output = "I dont know what you want to play."        if silent_mode == False:          handler_input.response_builder.speak(speak_output).ask(speak_output).set_card(SimpleCard("Playing {}...".format(song_value), speak_output))            return handler_input.response_builder.response    #Pause Intent  @sb.request_handler(can_handle_func=is_intent_name("PauseIntent"))  def Pause_intent_handler(handler_input):      speak_output = "Paused."        if silent_mode == False:          handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Pause", speak_output))            return handler_input.response_builder.response    #Loop Intent  @sb.request_handler(can_handle_func=is_intent_name("LoopIntent"))  def Loop_intent_handler(handler_input):      speak_output = "Song loop enabled."        if silent_mode == False:          handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Loop", speak_output))      return handler_input.response_builder.response    #Restart Intent  @sb.request_handler(can_handle_func=is_intent_name("RestartIntent"))  def Restart_intent_handler(handler_input):      speak_output = "Restarting current song"        if silent_mode == False:          handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Restart", speak_output))      return handler_input.response_builder.response    #Resume Intent  @sb.request_handler(can_handle_func=is_intent_name("ResumeIntent"))  def Resume_intent_handler(handler_input):      speak_output = "Resumed."        if silent_mode == False:          handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Resume", speak_output))      return handler_input.response_builder.response    #Now Playing Intent  @sb.request_handler(can_handle_func=is_intent_name("NowPlayingIntent"))  def Now_Playing_intent_handler(handler_input):            if Current_song:          speak_output = "Now playing {}.".format(Current_song)      else:          speak_output = "There is nothing playing at the moment"        if silent_mode == False:          handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Now Playing", speak_output))      return handler_input.response_builder.response    #Print Intent  @sb.request_handler(can_handle_func=is_intent_name("PrintIntent"))  def Print_intent_handler(handler_input):      speak_output = "Printed."        if silent_mode == False:          handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Print", speak_output))      return handler_input.response_builder.response    #Remove Number Intent  @sb.request_handler(can_handle_func=is_intent_name("RemoveNumIntent"))  def Remove_Num_intent_handler(handler_input):      num_value = handler_input.request_envelope.request.intent.slots["MusicNum"].value            if num_value:          speak_output = "Removed song number {} from queue".format(num_value)      else:          speak_output = "There is no song in number {}".format(num_value)        if silent_mode == False:          handler_input.response_builder.speak(speak_output).ask(speak_output).set_card(SimpleCard("Remove", speak_output))      return handler_input.response_builder.response    #Remove Position Intent  @sb.request_handler(can_handle_func=is_intent_name("RemovePosIntent"))  def Remove_Pos_intent_handler(handler_input):      pos_value = handler_input.request_envelope.request.intent.slots["MusicPos"].value            if pos_value:          speak_output = "Removed {} song from queue.".format(pos_value)      else:          speak_output = "There is no {} song in queue.".format(pos_value)        if silent_mode == False:          handler_input.response_builder.speak(speak_output).ask(speak_output).set_card(SimpleCard("Remove", speak_output))      return handler_input.response_builder.response    #Remove All Intent  @sb.request_handler(can_handle_func=is_intent_name("RemoveALLIntent"))  def Remove_All_intent_handler(handler_input):      speak_output = "All songs removed from queue"        if silent_mode == False:          handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Remove", speak_output))      return handler_input.response_builder.response    #Back Intent  @sb.request_handler(can_handle_func=is_intent_name("BackIntent"))  def Back_intent_handler(handler_input):      speak_output = "Went back a song in queue."        if silent_mode == False:          handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Back", speak_output))      return handler_input.response_builder.response    #Skip Intent  @sb.request_handler(can_handle_func=is_intent_name("SkiptIntent"))  def Skip_intent_handler(handler_input):      speak_output = "Skipped."        if silent_mode == False:          handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Skip", speak_output))      return handler_input.response_builder.response    #Shuffle Intent  @sb.request_handler(can_handle_func=is_intent_name("ShuffleIntent"))  def Shuffle_intent_handler(handler_input):      speak_output = "Shuffled queue."        if silent_mode == False:          handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Shuffle", speak_output))      return handler_input.response_builder.response    #Skip to number Intent  @sb.request_handler(can_handle_func=is_intent_name("SkipToNumIntent"))  def Skip_To_Num_intent_handler(handler_input):      num_value = handler_input.request_envelope.request.intent.slots["MusicNum"].value            if num_value:          speak_output = "Skiped to song number {}.".format(num_value)      else:          speak_output = "There is no {} song in queue.".format(num_value)        if silent_mode == False:          handler_input.response_builder.speak(speak_output).ask(speak_output).set_card(SimpleCard("Skip To", speak_output))      return handler_input.response_builder.response    #Skip to position Intent  @sb.request_handler(can_handle_func=is_intent_name("SkipToPosIntent"))  def Skip_To_Pos_intent_handler(handler_input):      pos_value = handler_input.request_envelope.request.intent.slots["MusicPos"].value            if pos_value:          speak_output = "Skiped to {} song in queue.".format(pos_value)      else:          speak_output = "There is no {} song in queue.".format(pos_value)        if silent_mode == False:          handler_input.response_builder.speak(speak_output).ask(speak_output).set_card(SimpleCard("Skip To", speak_output))      return handler_input.response_builder.response    #Loop queue Intent  @sb.request_handler(can_handle_func=is_intent_name("LoopQueueIntent"))  def Loop_Queue_intent_handler(handler_input):      speak_output = "Looped queue."        if silent_mode == False:          handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Loop Queue", speak_output))      return handler_input.response_builder.response    #Silent Mode Intent  @sb.request_handler(can_handle_func=is_intent_name("SilentModeIntent"))  def Silent_Mode_intent_handler(handler_input):        silent_mode = True        return handler_input.response_builder.response    #Disconnect Intent  @sb.request_handler(can_handle_func=is_intent_name("DisconnectIntent"))  def Disconnect_intent_handler(handler_input):      speak_output = "Disconnected."        if silent_mode == False:          handler_input.response_builder.speak(speak_output).set_card(SimpleCard("Disconnect", speak_output))      return handler_input.response_builder.response    sa = SkillAdapter(skill=sb.create(), skill_id="amzn1.ask.skill.e5e95d9a-6047-41aa-96f1-879b88421432", app=app)    """/////////////////////////  //  Exception Handlers  //  ////////////////////////"""    #Exception Handler  @sb.exception_handler(can_handle_func=lambda i, e: True)  def all_exception_handler(handler_input, exception):        speech = "Sorry, there was some problem. Please try again!!"      handler_input.response_builder.speak(speech).ask(speech)        return handler_input.response_builder.response      @app.route("/")  def invoke_skill():      return sa.dispatch_request()  

I first assumed the problem was that I didn't have an Exeption Handler, but there was no change in the result since I implemented one.

Has anyone solved this issue or has any idea what my code is missing?

https://stackoverflow.com/questions/67030699/alexa-skills-kit-skill-execution-returned-an-exception-for-requestid-error April 10, 2021 at 12:07PM

没有评论:

发表评论