使用 flask-ask 和 ngrok 的 Alexa 技能开发
Alexa Skill Development using flask-ask and ngrok
我正尝试在 python 中使用 flask-ask 和 ngrok 开始为 alexa 开发一项技能。以下是我的代码:
from flask import Flask
from flask_ask import Ask, statement, question, session
import json
import requests
import time
import unidecode
app = Flask(__name__)
ask = Ask(app, "/reddit_reader")
def get_headlines():
titles = 'is this working'
return titles
@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():
headlines = get_headlines()
headline_msg = 'The current world news headlines are
{}'.format(headlines)
return statement(headline_msg)
@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)
代码在我的机器上运行良好,returns 如果我打印出来,输出是正确的。但是当我使用 ngrok 在亚马逊上部署它时,该技能会出现 HTTP 500 内部错误。我在文本和开发控制台中的 json 模拟器中都遇到了相同的 500 内部错误。
这是我的意图模式:
{
"intents": [
{
"intent": "YesIntent"
},
{
"intent": "NoIntent"
}
]
}
我在 python 提示中收到以下错误:
AttributeError: module 'lib' has no attribute 'X509V3_EXT_get
堆栈跟踪如下:
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 728, in _flask_view_func
ask_payload = self._alexa_request(verify=self.ask_verify_requests)
File "C:\Python36\lib\site-packages\flask_ask\core.py", line 662, in _alexa_request
cert = verifier.load_certificate(cert_url)
File "C:\Python36\lib\site-packages\flask_ask\verifier.py", line 21, in load_certificate
if not _valid_certificate(cert):
File "C:\Python36\lib\site-packages\flask_ask\verifier.py", line 63, in _valid_certificate
value = str(extension)
File "C:\Python36\lib\site-packages\OpenSSL\crypto.py", line 779, in __str__
return self._subjectAltNameString()
File "C:\Python36\lib\site-packages\OpenSSL\crypto.py", line 740, in _subjectAltNameString
method = _lib.X509V3_EXT_get(self._extension)
AttributeError: module 'lib' has no attribute 'X509V3_EXT_get'
点冻结输出:
aniso8601==1.2.0
asn1crypto==0.24.0
certifi==2018.1.18
cffi==1.11.5
chardet==3.0.4
click==6.7
cryptography==2.2
Flask==0.12.1
Flask-Ask==0.9.8
idna==2.6
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
pycparser==2.18
pyOpenSSL==17.0.0
python-dateutil==2.7.0
PyYAML==3.12
requests==2.18.4
six==1.11.0
Unidecode==1.0.22
urllib3==1.22
Werkzeug==0.14.1
我在 python 2.7 和 python 3.6 上都试过 运行。感谢任何帮助
运行 遇到同样的问题,你可以通过将密码降级到任何低于 2.2 的版本来解决这个问题。
pip install 'cryptography<2.2'
rpg711 获得所有功劳(请参阅原始 post 上的评论)
我可以确认这适用于密码学 2.1.4,不适用于 Python 3.7 和 Mac OS High Sierra 上的 2.5 或 2.6。但是在 Mac OS 上还有其他问题需要先解决。
我发现安装crypotgraphy 2.1.4 以错误结束(如下)。我在 flask-ask 项目一开始就遇到了这个错误,在开始编码之前必须手动安装需求。当我最终开始尝试 alexa 时,我遇到了与密码学 2.5 或 2.6 相同的 500 错误(如上所述)。所以读到它必须是 2.1.4 我在尝试安装该特定版本时总是遇到这个错误:
#include <openssl/opensslv.h>
^~~~~~~~~~~~~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
尝试了很多东西后,我尝试了此 post (https://github.com/pyca/cryptography/issues/3489) 中的具体建议。尝试导出 CPPFLAGS 和 LDFLAGS 似乎没有用,但是下面的
pip3 install cryptography==2.1.4 --global-option=build_ext --global-option="-L/usr/local/opt/openssl/lib" --global-option="-I/usr/local/opt/openssl/include"
恐怕我不能说我之前尝试过的东西,即 brew link openssl 和设置 CPPFLAGS 和 LDFLAGS 是否对最终结果有影响。然而,我没有像 post 那样更新 openssl。我希望这会有所帮助,但我不是从知识的角度进行操作,并且不确定我是否具备手动安装 opsenssl 的技能,如 post.
中进一步指出的那样
希望这对我几乎要放弃的人有所帮助。
顺便说一句:我发现使用 ngrok 的网络 interface/inspector 非常方便,即能够一次又一次地重播亚马逊请求对我来说非常非常方便,因为我在密码问题之前犯了其他错误。
参考这个link帮我解决了问题。 https://github.com/pyca/cryptography/issues/3489
基本上,通过 $ brew link openssl
在 mac 中 linking openssl 并安装 cryptography==2.1.4,问题就解决了。
在 debian linux 上,尝试使用
降级加密模块
pip install 'cryptography<2.2'
导致无法卸载旧模块的错误(我想我的版本是2.6.1)。我通过删除 cryptography 文件夹以及 /usr/lib/python3/dist-packages 中的 *-.egg 文件手动卸载了它。
然后,当我尝试安装较旧的密码模块时,我再次 运行 进入错误 "unable to build wheel",因为我缺少一些 headers。根据 cryptography module docs 一旦我 运行,
sudo apt-get install build-essential libssl-dev libffi-dev python3-dev
然后我终于能够安装密码模块版本 2.1.4,并且我的 alexa 技能正常工作。
我正尝试在 python 中使用 flask-ask 和 ngrok 开始为 alexa 开发一项技能。以下是我的代码:
from flask import Flask
from flask_ask import Ask, statement, question, session
import json
import requests
import time
import unidecode
app = Flask(__name__)
ask = Ask(app, "/reddit_reader")
def get_headlines():
titles = 'is this working'
return titles
@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():
headlines = get_headlines()
headline_msg = 'The current world news headlines are
{}'.format(headlines)
return statement(headline_msg)
@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)
代码在我的机器上运行良好,returns 如果我打印出来,输出是正确的。但是当我使用 ngrok 在亚马逊上部署它时,该技能会出现 HTTP 500 内部错误。我在文本和开发控制台中的 json 模拟器中都遇到了相同的 500 内部错误。
这是我的意图模式:
{
"intents": [
{
"intent": "YesIntent"
},
{
"intent": "NoIntent"
}
]
}
我在 python 提示中收到以下错误:
AttributeError: module 'lib' has no attribute 'X509V3_EXT_get
堆栈跟踪如下:
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 728, in _flask_view_func
ask_payload = self._alexa_request(verify=self.ask_verify_requests)
File "C:\Python36\lib\site-packages\flask_ask\core.py", line 662, in _alexa_request
cert = verifier.load_certificate(cert_url)
File "C:\Python36\lib\site-packages\flask_ask\verifier.py", line 21, in load_certificate
if not _valid_certificate(cert):
File "C:\Python36\lib\site-packages\flask_ask\verifier.py", line 63, in _valid_certificate
value = str(extension)
File "C:\Python36\lib\site-packages\OpenSSL\crypto.py", line 779, in __str__
return self._subjectAltNameString()
File "C:\Python36\lib\site-packages\OpenSSL\crypto.py", line 740, in _subjectAltNameString
method = _lib.X509V3_EXT_get(self._extension)
AttributeError: module 'lib' has no attribute 'X509V3_EXT_get'
点冻结输出:
aniso8601==1.2.0
asn1crypto==0.24.0
certifi==2018.1.18
cffi==1.11.5
chardet==3.0.4
click==6.7
cryptography==2.2
Flask==0.12.1
Flask-Ask==0.9.8
idna==2.6
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
pycparser==2.18
pyOpenSSL==17.0.0
python-dateutil==2.7.0
PyYAML==3.12
requests==2.18.4
six==1.11.0
Unidecode==1.0.22
urllib3==1.22
Werkzeug==0.14.1
我在 python 2.7 和 python 3.6 上都试过 运行。感谢任何帮助
运行 遇到同样的问题,你可以通过将密码降级到任何低于 2.2 的版本来解决这个问题。
pip install 'cryptography<2.2'
rpg711 获得所有功劳(请参阅原始 post 上的评论)
我可以确认这适用于密码学 2.1.4,不适用于 Python 3.7 和 Mac OS High Sierra 上的 2.5 或 2.6。但是在 Mac OS 上还有其他问题需要先解决。
我发现安装crypotgraphy 2.1.4 以错误结束(如下)。我在 flask-ask 项目一开始就遇到了这个错误,在开始编码之前必须手动安装需求。当我最终开始尝试 alexa 时,我遇到了与密码学 2.5 或 2.6 相同的 500 错误(如上所述)。所以读到它必须是 2.1.4 我在尝试安装该特定版本时总是遇到这个错误:
#include <openssl/opensslv.h>
^~~~~~~~~~~~~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
尝试了很多东西后,我尝试了此 post (https://github.com/pyca/cryptography/issues/3489) 中的具体建议。尝试导出 CPPFLAGS 和 LDFLAGS 似乎没有用,但是下面的
pip3 install cryptography==2.1.4 --global-option=build_ext --global-option="-L/usr/local/opt/openssl/lib" --global-option="-I/usr/local/opt/openssl/include"
恐怕我不能说我之前尝试过的东西,即 brew link openssl 和设置 CPPFLAGS 和 LDFLAGS 是否对最终结果有影响。然而,我没有像 post 那样更新 openssl。我希望这会有所帮助,但我不是从知识的角度进行操作,并且不确定我是否具备手动安装 opsenssl 的技能,如 post.
中进一步指出的那样希望这对我几乎要放弃的人有所帮助。
顺便说一句:我发现使用 ngrok 的网络 interface/inspector 非常方便,即能够一次又一次地重播亚马逊请求对我来说非常非常方便,因为我在密码问题之前犯了其他错误。
参考这个link帮我解决了问题。 https://github.com/pyca/cryptography/issues/3489
基本上,通过 $ brew link openssl
在 mac 中 linking openssl 并安装 cryptography==2.1.4,问题就解决了。
在 debian linux 上,尝试使用
降级加密模块pip install 'cryptography<2.2'
导致无法卸载旧模块的错误(我想我的版本是2.6.1)。我通过删除 cryptography 文件夹以及 /usr/lib/python3/dist-packages 中的 *-.egg 文件手动卸载了它。
然后,当我尝试安装较旧的密码模块时,我再次 运行 进入错误 "unable to build wheel",因为我缺少一些 headers。根据 cryptography module docs 一旦我 运行,
sudo apt-get install build-essential libssl-dev libffi-dev python3-dev
然后我终于能够安装密码模块版本 2.1.4,并且我的 alexa 技能正常工作。