From a7fde3207a6034f87ae6d8390cf0f959396cacba Mon Sep 17 00:00:00 2001 From: Alec Haring Date: Wed, 6 Aug 2025 00:13:20 -0400 Subject: [PATCH] Fixed 204 handling --- discord_webhook/async_webhook.py | 5 +++-- discord_webhook/webhook.py | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/discord_webhook/async_webhook.py b/discord_webhook/async_webhook.py index 250c658..2062669 100644 --- a/discord_webhook/async_webhook.py +++ b/discord_webhook/async_webhook.py @@ -116,8 +116,9 @@ async def execute(self, remove_embeds=False) -> "httpx.Response": if remove_embeds: self.remove_embeds() self.remove_files(clear_attachments=False) - if webhook_id := json.loads(response.content.decode("utf-8")).get("id"): - self.id = webhook_id + if response.content: # don't parse if response has no content (204 response code) + if webhook_id := json.loads(response.content.decode("utf-8")).get("id"): + self.id = webhook_id return response async def edit(self) -> "httpx.Response": diff --git a/discord_webhook/webhook.py b/discord_webhook/webhook.py index 8291814..6fae707 100644 --- a/discord_webhook/webhook.py +++ b/discord_webhook/webhook.py @@ -470,11 +470,12 @@ def execute(self, remove_embeds: bool = False) -> "requests.Response": if remove_embeds: self.remove_embeds() self.remove_files(clear_attachments=False) - response_content = json.loads(response.content.decode("utf-8")) - if webhook_id := response_content.get("id"): - self.id = webhook_id - if attachments := response_content.get("attachments"): - self.attachments = attachments + if response.content: # don't parse if response has no content (204 response code) + response_content = json.loads(response.content.decode("utf-8")) + if webhook_id := response_content.get("id"): + self.id = webhook_id + if attachments := response_content.get("attachments"): + self.attachments = attachments return response def edit(self) -> "requests.Response":