Forums

Discord OAuth error 429 (Rate limited)

I have a webapp that has a Discord OAuth, for that it sends request to https://discord.com/api/oauth2/token

When I try to authorize via Discord, it returns error 429 with retry-after being like 10-20 hours

Discord response: Retry-After: 38998 seconds, X-RateLimit-Reset: None, X-RateLimit-Limit: None, X-RateLimit-Remaining: None

When I was initially testing it on Pythonanywhere, it worked fine, no errors

Why that might happen, and what can I do to prevent this?

If you're getting rate limited by Discord there's nothing we can do. Check if you're not sending too many requests. There's also a possibility they're limiting cloud environments.

I checked that I am not sending many requests (1 in this case). If I were to guess, they rate limit because pythonanywhere apps share same ip, and it gets ip blocked

This would be fixed if I make them via proxy (aka send them to other machine that has unique ip), but I'm not sure that Pythonanywhere free account can send requests to addresses outside of https://www.pythonanywhere.com/whitelist/

  • discord.com is allow-listed on free PythonAnywhere accounts, so this is not us blocking the request. https://www.pythonanywhere.com/whitelist/

  • Free accounts send outbound traffic via shared proxy IPs. Discord appears to be rate-limiting that shared IP, which can result in long Retry-After values even if your app only makes a single request.

  • On a free account, the only workaround is to use a third-party proxy with its own IP. https://help.pythonanywhere.com/pages/StaticIPForExternalAllowlists/

  • Paid accounts have unrestricted outbound Internet access and do not use the free proxy, which often avoids this issue (though it’s not a guaranteed dedicated IP). https://help.pythonanywhere.com/pages/OutboundInternetAccess/

Seems like shared IP is the issue

I can't send requests to my laptop at home for example to send requests to Discord from there, because of whitelist, correct?

Correct