Add TooManyRequests Exception#112
Merged
Merged
Conversation
bboe
reviewed
May 26, 2021
Member
bboe
left a comment
There was a problem hiding this comment.
Other than the one suggestion I really like this PR. Thanks!
Comment on lines
+164
to
+169
| msg += ( | ||
| f". Please wait at least {float(self.retry_after)} seconds " | ||
| "before re-trying this request." | ||
| if self.retry_after | ||
| else "" | ||
| ) |
Member
There was a problem hiding this comment.
Suggested change
| msg += ( | |
| f". Please wait at least {float(self.retry_after)} seconds " | |
| "before re-trying this request." | |
| if self.retry_after | |
| else "" | |
| ) | |
| if self.retry_after: | |
| msg += f". Please wait at least {float(self.retry_after)} seconds before re-trying this request." |
Contributor
Author
There was a problem hiding this comment.
I can do that. I patterned it after the message in Redirect class, which also could be changed.
edfcbbb to
f52682f
Compare
bboe
approved these changes
Jun 5, 2021
Member
|
Looks like this needs a quick CHANGES.rst fix since the last merge. |
Member
|
Edit, since I'm here, I'll quickly fix this one so I can do a release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Feature Summary and Justification
This adds a TooManyRequests exception.
In PRAW's issue 1716, 429s are being returned because Reddit refuses to serve concurrent requests to the morechildren endpoint (see the note in the link), and returns a 429 when it does get concurrent requests. I was able to get a 429 error shortly after starting two instances of PRAW that simultaneously ran
I checked the ratelimit headers on the tape I made of this test and confirmed that the errors happened even with nearly all 600 requests remaining.
There are two kinds of 429 responses returned by Reddit: those that include retry-after headers, and those that don't. (Concurrent requests to the morechildren endpoint do not get retry-after headers). It wouldn't be hard to treat 429s as retry status if the response included a retry-after header, and as an exception status if the response didn't. This would be similar to how 5xx codes are treated. The rate limiter could be then adjusted to account for the presence of retry-after headers. However, since Reddit's rate limits are not always what they appear to be, this should be left for another day.
In the mean time, doing half of the above by just making 429s an exception status and adding a TooManyRequests class would not be a breaking change, since 429s already result in an assertion error.
The test
test_request__too__many_requests__without_retry_headerswas added in lieu of a test of concurrent requests to the morechildren endpoint, since the response bodies are the same.References