Skip to content

JSONDecodeError in handle_rate_limit when retrying #172

@jayqi

Description

@jayqi

I'm running into a JSONDecodeError inside handle_rate_limit. I'm presuming this is happening when I'm hitting my webhook's rate limit and the retry code is kicking in.

Version: 1.4.1

Traceback (most recent call last):
File "/opt/render/project/src/huntsite/organizers/services.py", line 32, in _post_message_worker
return webhook.execute()
~~~~~~~~~~~~~~~^^
File "/opt/render/project/src/.venv/lib/python3.13/site-packages/discord_webhook/webhook.py", line 461, in execute
response = self.handle_rate_limit(response, self.api_post_request)
File "/opt/render/project/src/.venv/lib/python3.13/site-packages/discord_webhook/webhook.py", line 426, in handle_rate_limit
errors = json.loads(response.content.decode("utf-8"))
File "/opt/render/project/python/Python-3.13.7/lib/python3.13/json/init.py", line 346, in loads
return _default_decoder.decode(s)
~~~~~~~~~~~~~~~~~~~~~~~^^^
File "/opt/render/project/python/Python-3.13.7/lib/python3.13/json/decoder.py", line 345, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/render/project/python/Python-3.13.7/lib/python3.13/json/decoder.py", line 363, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Here's my code for invoking the webhook:

def _post_message_worker(message: str):
    try:
        webhook = DiscordWebhook(
            url=settings.ORGANIZERS_DISCORD_WEBHOOK_URL,
            content=message,
            rate_limit_retry=True,
            timeout=5,
        )
        return webhook.execute()
    except Exception as e:
        logger.exception(
            f"Failed to post message to Discord webhook: {e}", event="discord_webhook_error"
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions