我正在使用 Python 创建 Amazon Alexa 技能,该技能可以从我公司的系统中查询一些信息。但是,当我尝试调用将返回访问令牌的 API 时,它向我显示错误“请求的技能响应存在问题。”
class LaunchRequestHandler(AbstractRequestHandler):
"""Handler for Skill Launch."""
def can_handle(self, handler_input):
return ask_utils.is_request_type("LaunchRequest")(handler_input)
def handle(self, handler_input):
username = "xxxx.xxxx"
password = "***********"
try:
response = requests.get(url="https://exemplo.com/de/url", auth=(username, password))
speak_output = f"Response: {response.text}"
except Exception as e:
speak_output = f"Exception: {e}"
return (
handler_input.response_builder
.speak(speak_output)
.set_should_end_session(True)
.ask(speak_output)
.response
)
return (
handler_input.response_builder
.speak(speak_output)
.ask(speak_output)
.response
)
我尝试调用随机互联网 API,效果非常好。我通过 Insomnia 访问了令牌 API,这也有效,所以问题不在于我的 API。我还尝试使用 async 和 wait,但这也生成了错误。
我不知道 Alexa 是否需要任何额外的配置来发出经过身份验证的请求,而且我在文档中找不到任何内容。
对我来说,您似乎可以通过使用浏览器来获取您正在寻找的数据,对吧?如果是这种情况,您可以尝试 https://curlconverter.com/ [本网站上的图片说明] 生成一个请求,该请求使用您的 cookie 作为身份验证。但是,可用性取决于身份验证 cookie 的持续时间,您可能需要每年或更频繁地重做一次请求。
我希望这有帮助!