我正在尝试使用亚马逊设备地址API获取设备的位置。我在代码中参考了这个答案:Get location from Alexa Skills Kit (ASK)
然而,当我运行代码时,我得到了一个AttributeError: 'NoneType' object has no attribute 'consentToken'。以下是堆栈跟踪:
Traceback (most recent call last):
File "C:\Python36\lib\site-packages\flask\app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Python36\lib\site-packages\flask\app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "C:\Python36\lib\site-packages\flask\app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Python36\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Python36\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "C:\Python36\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Python36\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Python36\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Python36\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Python36\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Python36\lib\site-packages\flask_ask\core.py", line 767, in _flask_view_func
result = self._map_intent_to_view_func(self.request.intent)()
File "C:\Python36\myfiles\redditreader.py", line 32, in share_headlines
location = get_alexa_location()
File "C:\Python36\myfiles\redditreader.py", line 14, in get_alexa_location
TOKEN = context.System.user.permissions.consentToken
AttributeError: 'NoneType' object has no attribute 'consentToken'我正在使用ngrok部署技能,并使用flask-ask进行开发。代码如下:
from flask import Flask
from flask_ask import Ask, statement, question, session, context
import json
import requests
import time
import unidecode
app = Flask(__name__)
ask = Ask(app, "/reddit_reader")
def get_alexa_location():
URL = "https://api.amazonalexa.com/v1/devices/{}/settings" \
"/address".format(context.System.device.deviceId)
TOKEN = context.System.user.permissions.consentToken
HEADER = {'Accept': 'application/json',
'Authorization': 'Bearer {}'.format(TOKEN)}
r = requests.get(URL, headers=HEADER)
if r.status_code == 200:
return(r.json())
@app.route('/')
def homepage():
return "hi there, how ya doin?"
@ask.launch
def start_skill():
welcome_message = 'Hello there, would you like the news?'
return question(welcome_message)
@ask.intent("YesIntent")
def share_headlines():
location = get_alexa_location()
city = "Your City is {}! ".format(location["city"].encode("utf-8"))
address = "Your address is {}! ".format(location["addressLine1"].encode("utf-8"))
speech = city + address
return statement(speech)
@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)我无法对上面链接的问题的答案发表评论,因为我还没有必要的声誉。谢谢你的帮助!
发布于 2018-03-21 05:33:21
在你的实现中
TOKEN = context.System.user.permissions.consentTokenconsentToken为空,因为您没有访问该用户地址的权限。
您需要先向亚马逊开发人员门户网站(https://developer.amazon.com/edw/home.html#/skills)申请用户地址的权限。
发布于 2020-09-14 22:55:18
https://stackoverflow.com/questions/49394126
复制相似问题