500 internal server error on /api/alexa/smart_home

First post here, please don’t flame if i’m missing some info…

I’m trying to set up the Alexa smart home skill, and couldn’t get past the 401 errors when not supplying a long lived access token. So i generated one, passed it to my lambda function, and now I get a 500 RC, “Server got itself in trouble”

So I took a few steps back, and wrote some code to test the API locally. My instance is running via nginx reverse proxy, with 443 fwd’ed to 8123, and letsencrypt for ssl. So I start testing using the local hostname:8123 and NO_VERIFY_SSL, and get the same results.

When using PUT and URI = <home assistant>/api/ i get API running while supplying a header containing a valid token. Change the token and i’m getting a 401. So we know that token auth is working. When I invoke PUT against .../api/states i get a list of all the the entities and their states (also fails with a bad token).

But when I run a GET against .../api/alexa i get 405: Method Not Allowed – using POST (which is what the lambda function is using in the instructions, per matt2005) i get 500 Internal Server Error Server got itself in trouble

HA logs show a bunch of fails, including:

[homeassistant.components.alexa.auth] Token invalid and no refresh token available

and

ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 73, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 125, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/alexa/intent.py", line 56, in post
    message = await request.json()
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_request.py", line 584, in json
    return loads(body)
  File "/usr/local/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

There’s a bunch of other logs that seem to show that HA is trying to send change reports (don’t know what this means, really)

[homeassistant.components.alexa.state_report] Sent: {"event": {"header": {"namespace": "Alexa", "name": "ChangeReport", "messageId": "d3ba4440-ed9d-463b-86b7-314fa99b7464", "payloadVersion": "3"}, "payload": {"change": {"cause": {"type": "APP_INTERACTION"}, "properties": [{"name": "connectivity", "namespace": "Alexa.EndpointHealth", "value": {"value": "OK"}, "timeOfSample": "2020-04-27T04:53:28.0Z", "uncertaintyInMilliseconds": 0}]}}, "endpoint": {"scope": {"type": "BearerToken", "token": null}, "endpointId": "camera#radar_new_york_animated"}}}

I’m probably missing something silly, but looking for any advice that I can get.

Hi Chris,

I have exactly the same problem, but Alexa worked before :

  • at the first setup of the skill and the lambda, it works as expected (401 if no LLAT, discovered entities)
  • one week after, I tried to add some new entities : no luck, it doesn’t work (no discovered entities)
  • but in the same time, entities already in Alexa work as expected
  • I tried a lot of manipulations (restart HA, restart Echo, deactivation/activation of the skill, delete already discovered entities, generate new LLAT, etc), but without success
  • now, I have error 500 when I add a LLAT in lambda
  • even past discovered entities are not discoverable again.

In HA, I have a “Error when sending ChangeReport to Alexa: INVALID_ACCESS_TOKEN_EXCEPTION: Access token is not valid.”

I donlt now how to resolve it.
Any help would be greatly apprecied :wink:

I tried Haaska today : also an error 500.

I saw somewhere that reverse proxy can cause this, but why now ?
I also saw some GitHub open issues : maybe a HA release that cause this problem ?