alexa-samples / alexa-smarthome

Resources for Alexa Smart Home developers.
https://alexa.design/smarthome
Other
680 stars 336 forks source link

[Step 6.2.7] Failed when linking account error - for those that cannot follow instructions :-) #130

Closed dougie181 closed 4 years ago

dougie181 commented 4 years ago

Was not able to account link - got this error

We were unable to link Sample Smart Home Skill at this time.

Looking at the logs from the SampleSkillAdaptor lambda, I see that it receives the following directive, which looks correct. `{

"directive": {
    "header": {
        "namespace": "Alexa.Authorization",
        "name": "AcceptGrant",
        "messageId": "a85e1c84-a04e-4f7b-a307-70f7d5fc66c6",
        "payloadVersion": "3"
    },
    "payload": {
        "grant": {
            "type": "OAuth2.AuthorizationCode",
            "code": "#####################"
        },
        "grantee": {
            "type": "BearerToken",
            "token": "Atza|I#################"
        }
    }
}

}`

The return response shows the following error:

ERROR skill.index.handler.error: HTTP Error 403: Forbidden

An error occurred during JSON serialization of response: <HTTPError 403: 'Forbidden'> is not JSON serializable
Traceback (most recent call last):
File "/var/lang/lib/python3.6/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/var/lang/lib/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/var/lang/lib/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/var/runtime/awslambda/bootstrap.py", line 134, in decimal_serializer
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <HTTPError 403: 'Forbidden'> is not JSON serializable

Following the breadcrumbs, as the SampleSkillAdaptor lambda, simply passes on the directive to an API https://######.execute-api.us-east-1.amazonaws.com/prod/directives, which in turn talks to the SampleEndPointAdaptor lambda, I see that it receives the original directive correctly in its body :-)

All good so far...

Debugging the code further I discover that it fails when it gets to following code in the SampleEndPointAdaptor lambda

# Get the API ID, Client ID, and Client Secret
env_api_id = os.environ.get('api_id', None)
env_client_id = os.environ.get('client_id', None)
env_client_secret = os.environ.get('client_secret', None)

It is expecting to have the client_id and client_secret as its local environment variables!!!

doh!! This means, I did not complete [step 6.1] correctly and ended up updating the local environment variables in the front end SampleSkillAdaptor lambda instead of the SampleEndPointAdaptor lambda.

I thought I would share this if anyone else made the same mistake I made...