Issue when calling REST API to run service mqtt/publish

Every time the HASS REST API interface is called like this:

curl -X POST \
     -H "Content-Type: application/json" \
     -H "x-ha-access: MY_PASSWORD" \
     -d '{"payload": "'"$free_space"'", "topic": "media_free_space”, "retain": "True"}' \
     http://MY_IP:8123/api/services/mqtt/publish > /dev/null 2>&1 &

I get error message: ‘Server got itself in trouble’ and this is what I see in home-assistant.log:

ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/deps/aiohttp/web_protocol.py", line 417, in start
    resp = yield from self._request_handler(request)
  File "/home/homeassistant/.homeassistant/deps/aiohttp/web.py", line 289, 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/homeassistant/lib/python3.4/site-packages/homeassistant/components/http/ban.py", line 58, in ban_middleware_handler
    return (yield from handler(request))
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/http/__init__.py", line 424, in handle
    result = yield from result
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/api.py", line 313, in post
    data = json.loads(body) if body else None
  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 359, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting ',' delimiter: line 1 column 53 (char 52)

Anyone has any idea on what may be causing this?

Thanks in advance for any help.

Check the quotes.

     -d '{"payload": "'"$free_space"'", "topic": "media_free_space”, "retain": "True"}'
                      ^             ^                             ^
1 Like

Issue was actually only on the topic ” rather than ", not on the payload. Damn macOS and automatic “correction”…

Thanks for helping me noticing it though.