接收错误 "There was a problem with the requested skill's response" 但 JSON 输出正确

Receiving error "There was a problem with the requested skill's response" but JSON output is correct

我收到错误“请求的技能的响应有问题”,这是由以下原因引起的 class:

    """Handler for Skill Launch."""
    def can_handle(self, handler_input):
        # type: (HandlerInput) -> bool

        return ask_utils.is_request_type("LaunchRequest")(handler_input)

    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        url = "http://www.sefaria.org/api/calendars/?timezone=America/Vancouver&custom=ashkenazi"
        response = requests.get(url).json()
        sefaria_info = response
        todays_weekday = datetime.date.today().isoweekday()

        todays_aliyah = (sefaria_info['calendar_items'][0]['extraDetails']['aliyot'][todays_weekday])
        todays_aliyah_url = todays_aliyah.replace(" ", ".")
        todays_aliyah_url = 'https://www.sefaria.org/api/texts/' + todays_aliyah_url

        reading_response = requests.get(todays_aliyah_url).json()
        reading_text = (reading_response['text'])
        reading_text = ''.join(reading_text)

        speech = todays_aliyah + reading_text
        handler_input.response_builder.speak(speech).ask(speech)

        speak_output = "Welcome to the Daily Torah Portion Alexa Skill. Today's portion is" + todays_aliyah + reading_text

        return (
            handler_input.response_builder
                .speak(speak_output)
                .ask(speak_output)
                .response
        )

然而,JSON 输出似乎是有效的:

{
    "body": {
        "version": "1.0",
        "response": {
            "outputSpeech": {
                "type": "SSML",
                "ssml": "<speak>Welcome to the Daily Torah Portion Alexa Skill. Today's portion isDeuteronomy 30:1-30:6When all these things befall you—the blessing and the curse that I have set before you—and you take them to heart amidst the various nations to which the LORD your God has banished you,and you return to the LORD your God, and you and your children heed His command with all your heart and soul, just as I enjoin upon you this day,then the LORD your God will restore your fortunes<i></i> and take you back in love. He will bring you together again from all the peoples where the LORD your God has scattered you.Even if your outcasts are at the ends of the world,<i></i> from there the LORD your God will gather you, from there He will fetch you.And the LORD your God will bring you to the land that your fathers possessed, and you shall possess it; and He will make you more prosperous and more numerous than your fathers.Then the LORD your God will open up<i></i> your heart and the hearts of your offspring to love the LORD your God with all your heart and soul, in order that you may live.The LORD your God will inflict all those curses upon the enemies and foes who persecuted you.You, however, will again heed the LORD and obey all His commandments that I enjoin upon you this day.And the LORD your God will grant you abounding prosperity in all your undertakings, in the issue of your womb, the offspring of your cattle, and the produce of your soil. For the LORD will again delight in your well-being, as He did in that of your fathers,since you will be heeding the LORD your God and keeping His commandments and laws that are recorded in this book of the Teaching—once you return to the LORD your God with all your heart and soul.Surely, this Instruction which I enjoin upon you this day is not too baffling for you, nor is it beyond reach.It is not in the heavens, that you should say, “Who among us can go up to the heavens and get it for us and impart it to us, that we may observe it?”Neither is it beyond the sea, that you should say, “Who among us can cross to the other side of the sea and get it for us and impart it to us, that we may observe it?”No, the thing is very close to you, in your mouth and in your heart, to observe it.See, I set before you this day life and prosperity, death and adversity.For<i></i> I command you this day, to love the LORD your God, to walk in His ways, and to keep His commandments, His laws, and His rules, that you may thrive and increase, and that the LORD your God may bless you in the land that you are about to enter and possess.But if your heart turns away and you give no heed, and are lured into the worship and service of other gods,I declare to you this day that you shall certainly perish; you shall not long endure on the soil that you are crossing the Jordan to enter and possess.I call heaven and earth to witness against you this day: I have put before you life and death, blessing and curse. Choose life—if you and your offspring would live—by loving the LORD your God, heeding His commands, and holding fast to Him. For thereby you shall have life and shall long endure upon the soil that the LORD swore to your ancestors, Abraham, Isaac, and Jacob, to give to them.</speak>"
            },
            "reprompt": {
                "outputSpeech": {
                    "type": "SSML",
                    "ssml": "<speak>Welcome to the Daily Torah Portion Alexa Skill. Today's portion isDeuteronomy 30:1-30:6When all these things befall you—the blessing and the curse that I have set before you—and you take them to heart amidst the various nations to which the LORD your God has banished you,and you return to the LORD your God, and you and your children heed His command with all your heart and soul, just as I enjoin upon you this day,then the LORD your God will restore your fortunes<i></i> and take you back in love. He will bring you together again from all the peoples where the LORD your God has scattered you.Even if your outcasts are at the ends of the world,<i></i> from there the LORD your God will gather you, from there He will fetch you.And the LORD your God will bring you to the land that your fathers possessed, and you shall possess it; and He will make you more prosperous and more numerous than your fathers.Then the LORD your God will open up<i></i> your heart and the hearts of your offspring to love the LORD your God with all your heart and soul, in order that you may live.The LORD your God will inflict all those curses upon the enemies and foes who persecuted you.You, however, will again heed the LORD and obey all His commandments that I enjoin upon you this day.And the LORD your God will grant you abounding prosperity in all your undertakings, in the issue of your womb, the offspring of your cattle, and the produce of your soil. For the LORD will again delight in your well-being, as He did in that of your fathers,since you will be heeding the LORD your God and keeping His commandments and laws that are recorded in this book of the Teaching—once you return to the LORD your God with all your heart and soul.Surely, this Instruction which I enjoin upon you this day is not too baffling for you, nor is it beyond reach.It is not in the heavens, that you should say, “Who among us can go up to the heavens and get it for us and impart it to us, that we may observe it?”Neither is it beyond the sea, that you should say, “Who among us can cross to the other side of the sea and get it for us and impart it to us, that we may observe it?”No, the thing is very close to you, in your mouth and in your heart, to observe it.See, I set before you this day life and prosperity, death and adversity.For<i></i> I command you this day, to love the LORD your God, to walk in His ways, and to keep His commandments, His laws, and His rules, that you may thrive and increase, and that the LORD your God may bless you in the land that you are about to enter and possess.But if your heart turns away and you give no heed, and are lured into the worship and service of other gods,I declare to you this day that you shall certainly perish; you shall not long endure on the soil that you are crossing the Jordan to enter and possess.I call heaven and earth to witness against you this day: I have put before you life and death, blessing and curse. Choose life—if you and your offspring would live—by loving the LORD your God, heeding His commands, and holding fast to Him. For thereby you shall have life and shall long endure upon the soil that the LORD swore to your ancestors, Abraham, Isaac, and Jacob, to give to them.</speak>"
                }
            },
            "shouldEndSession": false,
            "type": "_DEFAULT_RESPONSE"
        },
        "sessionAttributes": {},
        "userAgent": "ask-python/1.11.0 Python/3.7.8"
    }
}

我尝试了以下代码,效果很好,但我想显示从 API 中提取的信息的文本,以及它的 JSON 值。

class LaunchRequestHandler(AbstractRequestHandler):
    """Handler for Skill Launch."""
    def can_handle(self, handler_input):
        # type: (HandlerInput) -> bool

        return ask_utils.is_request_type("LaunchRequest")(handler_input)

    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        url = "http://www.sefaria.org/api/calendars/?timezone=America/Vancouver&custom=ashkenazi"
        response = requests.get(url).json()
        sefaria_info = response
        todays_weekday = datetime.date.today().isoweekday()

        todays_aliyah = (sefaria_info['calendar_items'][0]['extraDetails']['aliyot'][todays_weekday])
        todays_aliyah_url = todays_aliyah.replace(" ", ".")
        todays_aliyah_url = 'https://www.sefaria.org/api/texts/' + todays_aliyah_url

        reading_response = requests.get(todays_aliyah_url).json()
        reading_text = (reading_response['text'])
        reading_text = ''.join(reading_text)

        speech = todays_aliyah + reading_text
        handler_input.response_builder.speak(speech).ask(speech)

        speak_output = "Welcome to the Daily Torah Portion Alexa Skill. Today's portion is" + todays_aliyah

        return (
            handler_input.response_builder
                .speak(speak_output)
                .ask(speak_output)
                .response
        )

编辑:我发现错误:

Invalid SSML Output Speech for requestId amzn1.echo-api.request.81de37b4-5ff5-4e6f-b77f-567758593c3d. Error: Invalid SSML element i" 

也在设备日志中。

通过添加以下行解决:

reading_text = reading_text.replace("<i>", "")
reading_text = reading_text.replace("</i>", "")