diff options
| author | Rapptz <[email protected]> | 2021-04-15 08:34:58 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2021-04-15 08:34:58 -0400 |
| commit | 1f74b051a8c12ab5f65b4a6c9a7a9f3ea423d421 (patch) | |
| tree | 8a09b3a028ca5c7b99880ca11234a28ce4c3ed88 /discord/webhook | |
| parent | Rewrite webhooks to play better with typings and rate limits (diff) | |
| download | discord.py-1f74b051a8c12ab5f65b4a6c9a7a9f3ea423d421.tar.xz discord.py-1f74b051a8c12ab5f65b4a6c9a7a9f3ea423d421.zip | |
Fix rate limit handling with retry_after precision change
Diffstat (limited to 'discord/webhook')
| -rw-r--r-- | discord/webhook/async_.py | 6 | ||||
| -rw-r--r-- | discord/webhook/sync.py | 6 |
2 files changed, 8 insertions, 4 deletions
diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index 6a68aede..296cccde 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -165,7 +165,7 @@ class AsyncWebhookAdapter: remaining = response.headers.get('X-Ratelimit-Remaining') if remaining == '0' and response.status != 429: - delta = utils._parse_ratelimit_header(response.headers) + delta = utils._parse_ratelimit_header(response) log.debug( 'Webhook ID %s has been pre-emptively rate limited, waiting %.2f seconds', webhook_id, delta ) @@ -178,9 +178,10 @@ class AsyncWebhookAdapter: if not response.headers.get('Via'): raise HTTPException(response, data) - retry_after = data['retry_after'] / 1000.0 # type: ignore + retry_after: float = data['retry_after'] # type: ignore log.warning('Webhook ID %s is rate limited. Retrying in %.2f seconds', webhook_id, retry_after) await asyncio.sleep(retry_after) + continue if response.status >= 500: await asyncio.sleep(1 + attempt * 2) @@ -195,6 +196,7 @@ class AsyncWebhookAdapter: except OSError as e: if attempt < 4 and e.errno in (54, 10054): + await asyncio.sleep(1 + attempt * 2) continue raise diff --git a/discord/webhook/sync.py b/discord/webhook/sync.py index b5d0bbce..c2f4d15b 100644 --- a/discord/webhook/sync.py +++ b/discord/webhook/sync.py @@ -156,7 +156,7 @@ class WebhookAdapter: remaining = response.headers.get('X-Ratelimit-Remaining') if remaining == '0' and response.status_code != 429: - delta = utils._parse_ratelimit_header(response.headers) + delta = utils._parse_ratelimit_header(response) log.debug( 'Webhook ID %s has been pre-emptively rate limited, waiting %.2f seconds', webhook_id, delta ) @@ -169,9 +169,10 @@ class WebhookAdapter: if not response.headers.get('Via'): raise HTTPException(response, data) - retry_after = data['retry_after'] / 1000.0 # type: ignore + retry_after: float = data['retry_after'] # type: ignore log.warning('Webhook ID %s is rate limited. Retrying in %.2f seconds', webhook_id, retry_after) time.sleep(retry_after) + continue if response.status_code >= 500: time.sleep(1 + attempt * 2) @@ -186,6 +187,7 @@ class WebhookAdapter: except OSError as e: if attempt < 4 and e.errno in (54, 10054): + time.sleep(1 + attempt * 2) continue raise |