question

newuser-13532822-5854-4fb4-88bd-19958443a0fc avatar image
newuser-13532822-5854-4fb4-88bd-19958443a0fc asked ·

python progressive response returning 400 Bad Request

I've been trying to send a progressive response in Lambda running python 3.6. Here's the code snippet:

def speak(message, request, context):
    endpoint = context['System']['apiEndpoint']
    accessToken = context['System']['apiAccessToken']
    requestId = request['requestId']

    directiveData = {
        "header":{
            "requestId": "{}".format(requestId)
        },
        "directive":{
            "type": "VoicePlayer.Speak",
            "speech": "{}".format(message)
        }
    }

    request = urllib.request.Request(url = endpoint + DIRECTIVES, data = urllib.parse.urlencode(directiveData).encode('utf-8'))
    request.add_header('Authorization', 'Bearer ' + accessToken)
    request.add_header('Content-Type', 'application/json')

    try:
        response = urllib.request.urlopen(request)
    except urllib.error.HTTPError as err:
        LOG.error("failed to send speak directive: {} {}".format(err.code, err.reason))

which is called with

speech.speak("Checking.", event['request'], event['context'])

The above code when called from my Lambda handler will always return with a 400 Bad Request. I've tried different variations of payload encoding, but none of them work. The example above seem to be the "most correct". Can anyone see what I am doing wrong? I've checked this code dozens of times against the official documentation and other examples, but I can't figure out what is wrong with it.

alexa skills kitresponsepythonprogressiveresponse
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

roy-1 avatar image
roy-1 answered ·

Hello,

I've posted some sample code for using the Progressive Response API with the ASK SDK for Python (Beta) in the following thread:

https://forums.developer.amazon.com/questions/181267/new-sdk-and-python-36-progressive-response-sample.html

Please let me know if that helps.

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

newuser-13532822-5854-4fb4-88bd-19958443a0fc avatar image
newuser-13532822-5854-4fb4-88bd-19958443a0fc answered ·

Is the ASK SDK for Python available in AWS Lambda? If not, that option doesn't apply to me.

What I've been trying to do is derived directly from the official documentation on progressive response, which operates at a lower level than the SDK. In fact, is the SDK available on github? If I can look at the internals of SendDirectiveRequest or directive_service_client.enqueue maybe I can figure out what I'm doing wrong. I looked around and found alexa-skills-kit-sdk-for-python but it doesn't seem to contain the implementation code.

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

roy-1 avatar image
roy-1 answered ·

You've got the right link to the GitHub repository for the ASK SDK for Python, which is currently in Beta. The documentation for the SDK can be found here:

https://alexa-skills-kit-python-sdk.readthedocs.io/en/latest/index.html

You'd currently be able to deploy a skill which uses this SDK to Lambda by creating a deployment package. In the Getting Started Tutorial from the documentation, there is a section that walks through this part. Please see the following link for more info:

https://alexa-skills-kit-python-sdk.readthedocs.io/en/latest/DEVELOPING_YOUR_FIRST_SKILL.html#preparing-your-code-for-aws-lambda

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.