Repository: praw-dev/praw

Issue:
Assertion error on 429 HTTP status code
**Describe the bug**
From time to time, I found my codes reported 429 errors.

**To Reproduce**
Steps to reproduce the behavior:
`submission.comments.replace_more(limit=limit)` with a higher limit for the query, running multiple processes for the same key.

**Expected behavior**
Expect to handle this error as ratelimit error

**Code/Logs**
<!-- include your code, without the Reddit() initialization, so as to not leak private credentials. -->
    submission.comments.replace_more(limit=limit)
  File "/usr/local/lib/python3.7/site-packages/praw/models/comment_forest.py", line 178, in replace_more
    new_comments = item.comments(update=False)
  File "/usr/local/lib/python3.7/site-packages/praw/models/reddit/more.py", line 74, in comments
    self._comments = self._reddit.post(API_PATH["morechildren"], data=data)
  File "/usr/local/lib/python3.7/site-packages/praw/reddit.py", line 758, in post
    path=path,
  File "/usr/local/lib/python3.7/site-packages/praw/reddit.py", line 672, in _objectify_request
    path=path,
  File "/usr/local/lib/python3.7/site-packages/praw/reddit.py", line 855, in request
    json=json,
  File "/usr/local/lib/python3.7/site-packages/prawcore/sessions.py", line 331, in request
    url=url,
  File "/usr/local/lib/python3.7/site-packages/prawcore/sessions.py", line 265, in _request_with_retries
    ), f"Unexpected status code: {response.status_code}"
AssertionError: Unexpected status code: 429
**System Info**

root@1be190a235da:/aitrading# uname -a
Linux 1be190a235da 4.19.0-14-cloud-amd64 #1 SMP Debian 4.19.171-2 (2021-01-30) x86_64 GNU/Linux
root@1be190a235da:/aitrading# python --version
Python 3.7.10
root@1be190a235da:/aitrading# pip show praw
Name: praw
Version: 7.2.0
Summary: PRAW, an acronym for `Python Reddit API Wrapper`, is a python package that allows for simple access to reddit's API.
Home-page: UNKNOWN
Author: Bryce Boe
Author-email: bbzbryce@gmail.com
License: Simplified BSD License
Location: /usr/local/lib/python3.7/site-packages
Requires: prawcore, update-checker, websocket-client
Required-by:
root@1be190a235da:/aitrading#

 - OS: 
 - Python: python3.7
 - PRAW Version:



Discussion:
Do you have a specific post that this occurs on?
Here are the `subs` and `flairs` I am using:
```
subs = ['wallstreetbets', 'stocks', 'investing', 'stockmarket']  # sub-reddit to search
# subs = ['wallstreetbets']  # sub-reddit to search
post_flairs = {'Daily Discussion', 'Weekend Discussion',
               'Discussion'}  # posts flairs to search || None flair is automatically considered
```
Fascinating. So this issue is likely happening because with multiple bots using the same credentials, that you are exceeding the simple API rate limit. The tricky bit here is that the relevant request _should_ be retried 2 times after sleeping an appropriate amount before raising said exception. This observation indicates whatever process is getting this exception is likely being starved by successful requests happening in the other processes. Short of coordinating requests like PRAW<4 did via the multiprocessing_proxy there's not really a great way to ensure a process isn't being starved.

How many processes are you running? Do you observe that some of the processes seem to make more requests than others?
This issue is stale because it has been open for 20 days with no activity. Remove the Stale label or comment or this will be closed in 10 days.

Resolving patch:
diff --git a/praw/models/comment_forest.py b/praw/models/comment_forest.py
--- a/praw/models/comment_forest.py
+++ b/praw/models/comment_forest.py
@@ -124,6 +124,8 @@ def replace_more(
 
         :returns: A list of :class:`.MoreComments` instances that were not replaced.
 
+        :raises: ``prawcore.TooManyRequests`` when used concurrently.
+
         For example, to replace up to 32 :class:`.MoreComments` instances of a
         submission try:
 
@@ -144,9 +146,8 @@ def replace_more(
         .. note::
 
             This method can take a long time as each replacement will discover at most
-            20 new :class:`.Comment` or :class:`.MoreComments` instances. As a result,
-            consider looping and handling exceptions until the method returns
-            successfully. For example:
+            100 new :class:`.Comment` instances. As a result, consider looping and
+            handling exceptions until the method returns successfully. For example:
 
             .. code-block:: python
 


Test patch: