Alexa API endpoint method not allowed

Here’s the intent schema over at Amazon:

{
  "intents": [
{
  "intent": "ActivateSceneIntent",
  "slots":
  [
    {
      "name" : "Scene",
      "type" : "Scenes"
    }
  ]
},
{
      "intent": "QueryLockIntent"
    }
  ]
}

I’m using slots for the scene names.

Having the same issue here, both on my previous instance and now a fresh installation from the HaSSbian image.

I thought it might have something to do with my nginx reverse proxy config, but it sounds like other people here are seeing the same thing with built in https.

Add me to the list of people seeing this issue. I too have the annoying requirement that internal and external port numbers must match so I can’t redirect 443->8123 as suggested. Hoping for another solution.

Ok I figured this out by looking at the alexa.py code

So the “Method Not Allowed” error is due to the fact that the alexa API can only handle POST requests and not GET requests. So when you type the URL in your browser that is using the GET request method which is indeed unsupported.

In order to test your Alexa skill, you can use a tool that can send POST requests, for example: https://www.getpostman.com/

Once I got over this hurdle I still hit another hurdle, which was the fact that Amazon does not like to use a non-standard port. So you have to make sure to port forward port HOST:443 to the internal IP:PORT where you have Home Assistant running with SSL enabled.

Which is what I said 26 days ago. :wink:

Yes Robert I saw the discussion on ports you guys had. His original issue was purely GET vs POST.

My issue with the ports was a bit different in nature as well. I wanted to be able to use the same URL for accessing my Home Assistant frontend regardless of being internal or external to my home network. With the Netgear (WNDR3800) router I use not supporting loopback, I had to find a “trickier” way of handling it. I’ll go into the details in case there are others with a similar issue/desire.

So the Amazon skill only seems to work with port 443. So I set up port forwarding of 443->8123. With just that set up, if I was on my home wifi and tried to go to https://my.duckdns.org it would not use that port forward due to Netgear router not supporting loopback. However if I disabled wifi and used LTE it worked just fine. So my solution was to also set up a port forward 8123->443. That way I could always use https://my.duckdns.org:8123 regardless of my location, and Amazon is happy using https://my.duckdns.org.

Another solution I saw was to install dd-wrt on the router to enable the loopback support, but my workaround seemed like less work.
I hope that makes sense :slight_smile:

2 Likes

Hi

Anyone can confirm this ?

“AWS requires a ‘straight’ SSL path”

My ISP blocks port 443 and I am having the exact same problem as you guys…

From HA docs:

Amazon requires the endpoint of a skill to be hosted via SSL.

From Amazon Developers website developers.amazon.com

The service must accept requests on port 443.

From an article on the same site about testing a custom skill:

Error Card	                Possible Causes
Unexpected Communication Issue	Occurs if Alexa cannot connect to your service to send a request. This can happen for many reasons:

                                The endpoint specified in the configuration on the developer portal is incorrect.
                                The web service is not online.
                                **The endpoint is not configured to accept traffic over port 443.**

(Emphasis added by me)

From StackOverflow:

The Alexa service is strict regarding app endpoints. It will only call out using HTTPS on port 443 whether it’s calling an app during development or deployed to production.

Links supplied below since no matter how many times I say this I’m still not being believed.

Thanks for the links an information !!!

1 Like

me as well … trying to figure out what to so

Using post man in POST https://lastname.duckdns.org/api/alexa?api_password=secret

I receive this:

<html>
    <head>
        <title>500 Internal Server Error</title>
    </head>
    <body>
        <h1>500 Internal Server Error</h1>Server got itself in trouble
    </body>
</html>

Using post man in GET https://lastname.duckdns.org/api/alexa?api_password=secret

I receive this
405: Method Not Allowed

My alexa: in configuration is

alexa:
  intents:
    ActivateSceneIntent:
      action:
        service: scene.turn_on
        data_template:
          entity_id: scene.{{ Scene | replace(" ", "_") }}
      speech:
        type: plaintext
        text: OK

in the log I noticed this.

16-12-23 11:09:10 homeassistant.components.http: Serving /api/alexa to 192.168.1.253 (auth: True)
16-12-23 11:09:10 aiohttp.server: Error handling request
Traceback (most recent call last):
  File "/home/hass/.homeassistant/deps/aiohttp/web_server.py", line 61, in handle_request
    resp = yield from self._handler(request)
  File "/home/hass/.homeassistant/deps/aiohttp/web.py", line 249, in _handle
    resp = yield from handler(request)
  File "/usr/lib/python3.4/asyncio/coroutines.py", line 143, in coro
    res = yield from res
  File "/usr/lib/python3.4/asyncio/coroutines.py", line 143, in coro
    res = yield from res
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/http/__init__.py", line 427, in handle
    result = yield from result
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/alexa.py", line 136, in post
    data = yield from request.json()
  File "/home/hass/.homeassistant/deps/aiohttp/web_reqrep.py", line 384, in json
    return loads(body)
  File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

1

I am now also having a similiar issue. Amazon’s Service Simulator will not hit my endpoint. It simply states:

There was an error calling the remote endpoint, which returned HTTP 404 : Not Found

However, if I take the same URL, put it in Postman, POST to the URL with the same Service Request JSON, I get a good 200 response back.

I have a valid, signed SSL certificate in place and am going straight over 443. I don’t know what else to try since I cannot get any more details about the request Amazon is trying to make.

I’m also getting a Python error.

In the Amazon dev console, the Service Simulator is the first indicator of a problem.

In “Enter utterance” to test, I put in:

activate typical night

The Service Request spits out:

{
  "session": {
    "sessionId": "SessionId.32e606f1-6dcd-4553-81c4-33c3a3bc1ba4",
    "application": {
      "applicationId": "amzn1.ask.skill.454352a3-9a05-4e54-8182-6287d5364b90"
    },
    "attributes": {},
    "user": {
      "userId": "amzn1.ask.account.AHKWH7632FVDHHSXT343NQ7XKPZJEK4KLX35YRJN2SO46ZJ5HMXB27OM7FFKGCSRCET2QTW5QTNJTN2G43N575Z3OYSGE32POXQQPSQFDGCKULDCVUX5O3FSU6R6HV55NLIELDKFKJZRBN64RP6ZXIFX7Z2HUSGJ5XUD4IAZLDYEIFN5QXYWYHG33JE65CJTHNLD4M626WJTW6A"
    },
    "new": true
  },
  "request": {
    "type": "IntentRequest",
    "requestId": "EdwRequestId.4b5b1aef-cb65-4619-8440-99104e5be205",
    "locale": "en-US",
    "timestamp": "2016-12-30T07:00:49Z",
    "intent": {
      "name": "ActivateSceneIntent",
      "slots": {
        "Scene": {
          "name": "Scene",
          "value": "typical sleep"
        }
      }
    }
  },
  "version": "1.0"
} 

The Service Response says:

The remote endpoint could not be called, or the response it returned was invalid.

So I poked at it with curl:

curl -k -X POST https://REDACTED.dyndns.org/api/alexa?api_password=REDACTED

Interestingly, this gets a 500 error.

Server got itself in trouble

When this happens, the logs report a python error:

INFO:homeassistant.components.http:Serving /api/alexa to 50.46.133.153 (auth: True)
ERROR:aiohttp.web:Error handling request
Traceback (most recent call last):
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/aiohttp/server.py", line 261, in start
yield from self.handle_request(message, payload)
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/aiohttp/web.py", line 88, in handle_request
resp = yield from handler(request)
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/http.py", line 508, in handle
result = yield from result
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/alexa.py", line 136, in post
data = yield from request.json()
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/aiohttp/web_reqrep.py", line 321, in json
return loads(body)
File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

Now, the non-API URLS work. The web interface works just fine. https://REDACTED.dyndns.org, which I believe proves that my router port forwarding is set up correctly.

I’ll take a closer look at the source code later to see why it’s dying there.

Just an update that I fixed my problem. It was an issue with the SSL. Turns out that Amazon really wants you to use the configuration file method they detail at https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/testing-an-alexa-skill#create-a-private-key-and-self-signed-certificate-for-testing

He Guys,

if anyone get stuck with this error also. For me it was my API-Password. I had an # in my Password. This was my error, not the Lets encrypt Cert. If set an Password with only numbers and letters. Now it is working.

Hi guys,
I also had this “500 - Internal server error” issue… It has been caused by a wrong Intent configuration/wrong indent format of my configuration.yml -alexa-section.
Just make sure to use some very, very simple intent config during setup phase like:

alexa:
  intents:
    SpeakIntent:
      speech:
        type: plaintext
        text: This is magic 

This worked out finally… besides the 443-port issue, the exact (sub)domain name in the certificate and so on…

Cheers,
Bastian

I have the same “internal server error”.

This is my config:

alexa:
  intents:
    WhereAreWeIntent:
      speech:
        type: plaintext
        text: Lorem ipsum

Port 443 is redirected, and I can use iftt without any problems.

When I create a post request to https://redacted.com/api/alexa?api_password=redacted in the home-assistant.log the following error appears:

17-03-06 20:37:49 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/deps/aiohttp/web_server.py", line 62, in handle_request
    resp = yield from self._handler(request)
  File "/home/homeassistant/.homeassistant/deps/aiohttp/web.py", line 270, in _handle
    resp = yield from handler(request)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/http/ban.py", line 57, in ban_middleware_handler
    return (yield from handler(request))
  File "/usr/lib/python3.4/asyncio/coroutines.py", line 143, in coro
    res = yield from res
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/http/__init__.py", line 417, in handle
    result = yield from result
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/alexa.py", line 136, in post
    data = yield from request.json()
  File "/home/homeassistant/.homeassistant/deps/aiohttp/web_reqrep.py", line 405, in json
    return loads(body)
  File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

Any ideas?

Could you solve the problem?

Nope… and I haven’t tried since then.

I still have the 500-Error but the Alexa-Skill works right now.