Ironkey
Ironkey

Reputation: 2607

amazon alexa skill not properly running working python code

Im working on a simple amazon alexa skill in python. I have wrote all my code for this simple application and loaded it into my lambada function i have tested that lambada has loaded my imported libraries and that it works with them but when i use this final code it gets a "problem with the requested skills response"

    def handle(self, handler_input):
        # type: (HandlerInput) -> Response

        # https://repl.it/repls/UselessOptimalPipeline

        url = "http://jokepro.dx.am/"

        source = requests.get(url)
        bs4call = bs4.BeautifulSoup(source.text, "html.parser")

        obj = bs4call.find('object')

        text = requests.get(url + obj['data']).text
        # print(text) # <-- to print the textfile

        finalJoke = random.choice(text.splitlines())

        speak_output = finalJoke

        return (
            handler_input.response_builder
                .speak(speak_output)
                #.ask()
                .response
        )

this is the handler function

is lambada conflicting with anything in that code? why is it not working?

update: heres some relevant info

requirements.txt

boto3==1.9.216
ask-sdk-core==1.11.0
bs4==4.8.2
requests==2.22.0

Not Giving any response which signifies an error...

This was ALL dont through the amazon dev console https://developer.amazon.com/alexa/console/ask

Upvotes: 5

Views: 878

Answers (1)

KiteCoder
KiteCoder

Reputation: 2452

EDIT: My apologies for not requesting full detail of your issue

Based on my expirementation, your issue is related to the dependencies not being configured correctly. When deploying the function, ALL dependencies must be listed within the requriements.txt. In order to get the proper dependencies I would recommend using pipenv.

For Example the following commands will show you the complete dependency tree for your project:

  • pipenv install requests
  • pipenv install bs4
  • pipenv lock -r > requirements.txt

The result of these commands shows your requirements.txt file with the following dependencies as a result of adding those two libraries:

beautifulsoup4==4.8.2
bs4==0.0.1
certifi==2019.11.28
chardet==3.0.4
idna==2.8
requests==2.22.0
soupsieve==1.9.5
urllib3==1.25.8

All of which are required for your project to import the modules correctly. Of course you will also need your boto3 and ask-sdk in your requirements.txt, however, they are natively included in lambda so therefore you do not need the dependencies.

For any libraries that aren't natively included in lambda you will need to follow this procedure. For a list of libraries that are natively included please see: Lambda Packages.

Upvotes: 2

Related Questions