Home Assistant Receiving Webhook Error

Chaps

I’m trying to setup Webhooks between qBittorrent and HA.
I have this setup as an automation / actual webhook hidden for security

alias: Media <> Movies <> Plex 12 - qBittorrent Webhook Received = DO SOMETHING
description: ""
triggers:
  - trigger: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: true
    webhook_id: qbittorrent_example_webhook

If I fire a test Webhook from CMD Prompt (Windows) it sends OK and hits HA

curl -v POST -H "Content-Type: application/json" -d '{"message":"Hello World","test":123}' https://MY.duckdns.org:8123/api/webhook/qbittorrent_example_webhook


But I get this error in the HA Logs / and never triggers my automation
Just wondering if anyone has seen

Logger: homeassistant.components.webhook
Source: components/webhook/__init__.py:194
integration: Webhook (documentation, issues)
First occurred: 09:49:20 (13 occurrences)
Last logged: 10:29:35

Error processing webhook qbittorrent_example_webhook
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/webhook/__init__.py", line 194, in async_handle_webhook
    response: Response | None = await webhook["handler"](hass, webhook_id, request)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/webhook/trigger.py", line 68, in _handle_webhook
    base_result["json"] = json_loads(text) if text else {}
                          ~~~~~~~~~~^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/json.py", line 42, in json_loads
    return orjson.loads(obj)  # type:ignore[no-any-return]
           ~~~~~~~~~~~~^^^^^
orjson.JSONDecodeError: unexpected character: line 1 column 1 (char 0)

curl -v **-X** POST

Hey Chris, you’ve helped me before
And just want to say THANKS
So I tried that

curl -v **-X** POST -H "Content-Type: application/json" -d '{"message":"Hello World","test":123}' https://MY.duckdns.org:8123/api/webhook/qbittorrent_example_webhook

And got the same/similar error

Logger: homeassistant.components.webhook
Source: components/webhook/__init__.py:194
integration: Webhook (documentation, issues)
First occurred: 09:49:20 (15 occurrences)
Last logged: 11:09:15

Error processing webhook qbittorrent_torrent_added
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/webhook/__init__.py", line 194, in async_handle_webhook
    response: Response | None = await webhook["handler"](hass, webhook_id, request)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/webhook/trigger.py", line 68, in _handle_webhook
    base_result["json"] = json_loads(text) if text else {}
                          ~~~~~~~~~~^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/json.py", line 42, in json_loads
    return orjson.loads(obj)  # type:ignore[no-any-return]
           ~~~~~~~~~~~~^^^^^
orjson.JSONDecodeError: unexpected character: line 1 column 1 (char 0)

Brucey

I hope you understood the “*” were just for highlight? :wink:
So, actually, curl -v -X POST ...

1 Like

Sorry also tried

curl -v -X POST -H "Content-Type: application/json" -d '{"message":"Hello World","test":123}' https://MY.duckdns.org:8123/api/webhook/qbittorrent_example_webhook

Although the command went through quicker / sorry I don’t know curl commands

Did a quick test and works for me.
The error message points to some garbage on the data sent, but I can’t see it…

1 Like

Interesting
OK, thanks a lot mate, I’ll keep playing and come back to you if I need to
Now I know the correct syntax, hopefully I can get it working
THANKS AGAIN MATE

Honestly, as an old age dude (58 now), I’d be lost without you guys and all your help. Thanks a bunch. HNY BTW

Lol. Just passed 59 :smiley:

2 Likes

I love that mate . . . . . still smashing it at 59

OK, progress
This works and triggers my automation; no errors in the log

So it’s the message payload causing the problem
Any thoughts ?

curl -v -X POST -H "Content-Type: application/json" https://MY.duckdns.org:8123/api/webhook/qbittorrent_example_webhook

On Windows you need to use a different quoting style; the single quotes don’t work so you have to use double quotes on the outside and escape the ones on the inside.

curl -v -X POST -H "Content-Type: application/json" -d "{\"message\":\"Hello World\",\"test\":123}" https://MY.duckdns.org:8123/api/webhook/qbittorrent_example_webhook
1 Like

Thanks mate, back to back Zoom calls now, will try later
THANKYOU