Alexa Skill Development using flask-ask and ngrok
Asked Answered
E

4

11

I'm trying to begin developing a skill for alexa using flask-ask and ngrok in python. Following is my code:

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)

The code runs fine on my machine and returns the correct output if I print it out. But the skill gives a HTTP 500 internal error when I deploy it on amazon using ngrok. I get the same 500 internal error both in the text as well as json simulator in the development console.

This is my intent schema:

{
  "intents": [
    {
      "intent": "YesIntent"
    },
    {
      "intent": "NoIntent"
    }
  ]
}

I get the following error in my python prompt: AttributeError: module 'lib' has no attribute 'X509V3_EXT_get

The stacktrace is as follows:

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'

Pip freeze output:

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

I've tried running it on both python 2.7 and python 3.6. Any help is appreciated

Ellery answered 20/3, 2018 at 1:36 Comment(6)
What's the stacktrace?Shrive
added it to the questionEllery
Can you do a pip freeze and paste that output as well.Shrive
added pip freeze output tooEllery
Try uninstalling and downgrading cryptography to version 1.7 and see if that fixes this, pyOpenSSL requires 1.7 at a minimum, something may have been removed in the new cryptography module that the older v17.0.0 pyOpenSSL depends on.Shrive
It worked! I downgraded to 2.0 (tried 1.7, was getting some visual c++ error). Thanks a ton!Ellery
P
25

Ran into the same issue, you can fix it by downgrading cryptography to anything less than 2.2 for me.

pip install 'cryptography<2.2'

rpg711 gets all the credit (see comments the on original post)

Pieter answered 24/3, 2018 at 15:59 Comment(3)
voglster is correct, this also fixed it for me. Just as an FYI the current latest version that works is 2.1.4Janellajanelle
Does this only work for Python 2? I installed cryptography 2.1.4, 1.7 and I'm still getting this error.Tableau
Worked for me with 3.6 (with cryptography 2.1.4)Sealy
F
1

I can confirm that this works with cryptography 2.1.4, not with 2.5 or 2.6 on Python 3.7 and Mac OS High Sierra. However on Mac OS there are other issues to get over first.

What I found is that installing crypotgraphy 2.1.4 ends with an error (as below). I hit this error at the very start of my flask-ask project and had to do a manual install of requirements before I started coding. When I finally started trying alexa, I got the same 500 error (as above) with cryptography 2.5 or 2.6. So reading that it has to be 2.1.4 I always got this error when trying to install that specific version:

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

Having tried many things I tried the specific recommendation in this post (https://github.com/pyca/cryptography/issues/3489). Trying the export CPPFLAGS and LDFLAGS didn't seem to work, however the following did

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"

I am afraid I cannot say whether the things I tried before i.e. brew link openssl and setting the CPPFLAGS and LDFLAGS had an impact on the final result. I did not however do an update of openssl as in the post. I hope that helps, but I was not operating from a position of knowledge and was not sure whether I had the skills do a manual install of opsenssl as indicated further in the post.

I hope this helps as I had almost given up.

BTW: using ngrok's web interface/inspector I found really handy, i.e. being able to replay the amazon request time and time again was very, very handy for me as I made other errors before the cryptography issue.

Frisbee answered 14/2, 2019 at 19:4 Comment(0)
V
0

Referring to this link helped me solve the problem. https://github.com/pyca/cryptography/issues/3489

Basically, by linking openssl in mac by $ brew link openssland installing cryptography==2.1.4, the problem was resolved.

Vandyke answered 15/7, 2019 at 12:17 Comment(0)
R
0

On debian linux, attempting to downgrade the cryptography module with

pip install 'cryptography<2.2'

led to the errors of not being able to uninstall the old module (I think I had version 2.6.1). I uninstalled it manually by deleting the folders cryptography along with the *-.egg file within /usr/lib/python3/dist-packages.

Then, when I tried to install the older cryptography module, I again ran into an error "unable to build wheel" because I was missing some headers. According to the cryptography module docs Once I ran,

sudo apt-get install build-essential libssl-dev libffi-dev python3-dev

I was then finally able to install cryptography module version 2.1.4, and my alexa skill worked properly.

Rouen answered 4/5, 2020 at 5:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.