r/redditdev • u/itapebats • Jan 23 '18
PRAW PRAW 5.3.0 - TooLarge: received 413 HTTP response when using replace_more(limit=None)
I'm trying to pull all the comments from the 2017 Superbowl thread in /r/nfl
https://www.reddit.com/r/nfl/comments/5sapal/super_bowl_51_game_thread_new_england_patriots/
I'm getting an error "TooLarge: received 413 HTTP response" When trying to pull.
Is there any way around this. I've tried looking and can't find anyone else with the same issue.
Here is my code (Just an example where I am printing):
config = configparser.ConfigParser()
config.read('reddit.config')
reddit = praw.Reddit(client_id=config['REDDIT_CONFIG']['client_id'],
client_secret=config['REDDIT_CONFIG']['client_secret'],
password=config['REDDIT_CONFIG']['password'],
user_agent=config['REDDIT_CONFIG']['user_agent'],
username=config['REDDIT_CONFIG']['username'])
game_thread_url = 'https://www.reddit.com/r/nfl/comments/5sapal/super_bowl_51_game_thread_new_england_patriots/'
submission = reddit.submission(url=game_thread_url)
print("Number of Comments in Game Thread: {}".format(submission.num_comments))
submission.comments.replace_more(limit=None)
comment_queue = submission.comments[:] # Seed with top-level
while comment_queue:
comment = comment_queue.pop(0)
if isinstance(comment, MoreComments):
continue
print("=============NEW COMMMENT=============")
print('Comment ID:',comment)
print('Comment Body:', comment.body)
print('Comment Author:', comment.author)
print('Comment Author Flair CSS:',comment.author_flair_css_class)
print('Comment Author Flair Text',comment.author_flair_text)
print('Comment Body Controversaility:', comment.controversiality)
print('Comment Created:', comment.created)
print('Comment Created UTC:', comment.created_utc)
print('Comment Depth', comment.depth)
print('Comment Downvotes', comment.downs)
print('Comment UpVotes', comment.ups)
print('Comment Score', comment.score)
print('Comment Submission', comment.submission)
print('Comment User Reports', comment.user_reports)
print('Comment Subreddit', comment.subreddit)
print('Comment Post', comment.submission)
print('Submission Title: ', submission.title)
print('Submission Score: ', submission.score)
comment_queue.extend(comment.replies)
And the stacktrace: --------------------------------------------------------------------------- TooLarge Traceback (most recent call last) <ipython-input-20-e3b2017f4fce> in <module>() ----> 1 submission.comments.replace_more(limit=32) 2 comment_queue = submission.comments[:] # Seed with top-level 3 while comment_queue: 4 comment = comment_queue.pop(0) 5 if isinstance(comment, MoreComments):
~/miniconda3/envs/w266/lib/python3.6/site-packages/praw/models/comment_forest.py in replace_more(self, limit, threshold)
160 continue
161
--> 162 new_comments = item.comments(update=False)
163 if remaining is not None:
164 remaining -= 1
~/miniconda3/envs/w266/lib/python3.6/site-packages/praw/models/reddit/more.py in comments(self, update)
63 'sort': self.submission.comment_sort}
64 self._comments = self._reddit.post(API_PATH['morechildren'],
---> 65 data=data)
66 if update:
67 for comment in self._comments:
~/miniconda3/envs/w266/lib/python3.6/site-packages/praw/reddit.py in post(self, path, data, files, params)
429 """
430 data = self.request('POST', path, data=data or {}, files=files,
--> 431 params=params)
432 return self._objector.objectify(data)
433
~/miniconda3/envs/w266/lib/python3.6/site-packages/praw/reddit.py in request(self, method, path, params, data, files)
470 """
471 return self._core.request(method, path, data=data, files=files,
--> 472 params=params)
473
474 def submission( # pylint: disable=invalid-name,redefined-builtin
~/miniconda3/envs/w266/lib/python3.6/site-packages/prawcore/sessions.py in request(self, method, path, data, files, json, params)
179 return self._request_with_retries(
180 data=data, files=files, json=json, method=method,
--> 181 params=params, url=url)
182
183
~/miniconda3/envs/w266/lib/python3.6/site-packages/prawcore/sessions.py in _request_with_retries(self, data, files, json, method, params, url, retries)
124 retries, saved_exception, url)
125 elif response.status_code in self.STATUS_EXCEPTIONS:
--> 126 raise self.STATUS_EXCEPTIONS[response.status_code](response)
127 elif response.status_code == codes['no_content']:
128 return
TooLarge: received 413 HTTP response
2
u/bboe PRAW Author Jan 23 '18
The same 413 HTTP response happens when you hit "load more comments" directly on that page. I don't think Reddit's more comments interface is built to handle comment threads that large.
You can try fetching some of those comments directly, but such work arounds aren't something we'll add directly into PRAW. Maybe file a bug on /r/bugs?
2
u/Watchful1 RemindMeBot & UpdateMeBot Jan 24 '18
You can use pushshift as a workaround if you want. Something like this
https://api.pushshift.io/reddit/comment/search?link_id=5sapal&limit=500&sort=desc
and then use the "after" parameter with the utc time of the last comment to get the next set.