Skip to content

Commit 98cce42

Browse files
authored
Merge pull request #171 from AlecHaring/fix-204-handling
Fix 204 handling
2 parents 60a3a89 + a7fde32 commit 98cce42

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

discord_webhook/async_webhook.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ async def execute(self, remove_embeds=False) -> "httpx.Response":
116116
if remove_embeds:
117117
self.remove_embeds()
118118
self.remove_files(clear_attachments=False)
119-
if webhook_id := json.loads(response.content.decode("utf-8")).get("id"):
120-
self.id = webhook_id
119+
if response.content: # don't parse if response has no content (204 response code)
120+
if webhook_id := json.loads(response.content.decode("utf-8")).get("id"):
121+
self.id = webhook_id
121122
return response
122123

123124
async def edit(self) -> "httpx.Response":

discord_webhook/webhook.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,12 @@ def execute(self, remove_embeds: bool = False) -> "requests.Response":
470470
if remove_embeds:
471471
self.remove_embeds()
472472
self.remove_files(clear_attachments=False)
473-
response_content = json.loads(response.content.decode("utf-8"))
474-
if webhook_id := response_content.get("id"):
475-
self.id = webhook_id
476-
if attachments := response_content.get("attachments"):
477-
self.attachments = attachments
473+
if response.content: # don't parse if response has no content (204 response code)
474+
response_content = json.loads(response.content.decode("utf-8"))
475+
if webhook_id := response_content.get("id"):
476+
self.id = webhook_id
477+
if attachments := response_content.get("attachments"):
478+
self.attachments = attachments
478479
return response
479480

480481
def edit(self) -> "requests.Response":

0 commit comments

Comments
 (0)