Alexa Skill开发使用flask-ask和ngrok

问题描述 投票:9回答:2

我正在尝试使用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)

代码在我的机器上正常运行,如果我将其打印出来,则返回正确的输出。但是当我使用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上运行它。任何帮助表示赞赏

python alexa alexa-skill ngrok
2个回答
20
投票

遇到同样的问题,你可以通过将加密降级到任何低于2.2的任何东西来修复它。

pip install 'cryptography<2.2'

rpg711获得所有功劳(请参阅原帖上的评论)


1
投票

我可以确认这适用于加密2.1.4,而不是Python 3.7和Mac OS High Sierra上的2.5或2.6。但是在Mac OS上还有其他问题要先克服。

我发现安装crypotgraphy 2.1.4以错误结束(如下所示)。我在烧瓶问题项目的最开始就遇到了这个错误,并且在开始编码之前必须手动安装需求。当我最终开始尝试alexa时,我得到了与密码学2.5或2.6相同的500错误(如上所述)。所以阅读它必须是2.1.4我在尝试安装特定版本时总是遇到此错误:

    #include <openssl/opensslv.h>
             ^~~~~~~~~~~~~~~~~~~~
    1 error generated.
    error: command 'clang' failed with exit status 1

尝试了很多东西后,我尝试了这篇文章中的具体建议(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链接openssl以及设置CPPFLAGS和LDFLAGS是否会对最终结果产生影响。然而,我没有在帖子中更新openssl。我希望这有帮助,但我不是从知识的位置开始操作,也不确定我是否有技能手动安装opsenssl,如帖子中所示。

我希望这有助于我几乎放弃了。

BTW:使用ngrok的网络界面/检查员我发现非常方便,即能够一次又一次地重播亚马逊请求对我来说非常非常方便,因为我在加密问题之前犯了其他错误。


0
投票

参考此链接帮助我解决了这个问题。 https://github.com/pyca/cryptography/issues/3489

基本上,通过$ brew link openssland安装cryptography == 2.1.4连接mac中的openssl,问题得到了解决。

© www.soinside.com 2019 - 2024. All rights reserved.