Shreddit icon indicating copy to clipboard operation
Shreddit copied to clipboard

Suddenly failing

Open mkaatman opened this issue 3 years ago • 11 comments

Traceback (most recent call last):
  File "/home/user/.local/bin/shreddit", line 8, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python3.8/site-packages/shreddit/app.py", line 54, in main
    shredder.shred()
  File "/home/user/.local/lib/python3.8/site-packages/shreddit/shredder.py", line 68, in shred
    deleted = self._remove_things(self._build_iterator())
  File "/home/user/.local/lib/python3.8/site-packages/shreddit/shredder.py", line 171, in _remove_things
    self._remove(item)
  File "/home/user/.local/lib/python3.8/site-packages/shreddit/shredder.py", line 142, in _remove
    self._remove_comment(item)
  File "/home/user/.local/lib/python3.8/site-packages/shreddit/shredder.py", line 128, in _remove_comment
    comment.edit(replacement_text)
  File "/home/user/.local/lib/python3.8/site-packages/praw/models/reddit/mixins/editable.py", line 47, in edit
    updated = self._reddit.post(API_PATH["edit"], data=data)[0]
  File "/home/user/.local/lib/python3.8/site-packages/praw/reddit.py", line 665, in post
    return self._objectify_request(
  File "/home/user/.local/lib/python3.8/site-packages/praw/reddit.py", line 578, in _objectify_request
    self.request(
  File "/home/user/.local/lib/python3.8/site-packages/praw/reddit.py", line 758, in request
    return self._core.request(
  File "/home/user/.local/lib/python3.8/site-packages/prawcore/sessions.py", line 332, in request
    return self._request_with_retries(
  File "/home/user/.local/lib/python3.8/site-packages/prawcore/sessions.py", line 268, in _request_with_retries
    assert (
AssertionError: Unexpected status code: 429

mkaatman avatar Mar 30 '21 14:03 mkaatman

Reddit introduced rate-limiting on their API about 4 days ago. Rumor has it it was due to a bot earlier this week who edited comments with the usernames of every Reddit account to spam chat requests.

Current API limitations have write actions (post/edit) limited to 1 every 30 seconds. This isn't limited to apps, even old.reddit.com/ blocks users in the interface from editing more than once every 30 sec.

To fix, Shreddit will need to add a delay timer, hopefully with a programmable variable to be included in shreddit.yml.

Unfortunately, I think the app is no longer in development, so here's hoping some fork fixes it.

endeavor51 avatar Mar 30 '21 17:03 endeavor51

Should be fixed now.

https://old.reddit.com/r/redditdev/comments/mg077m/not_even_close_to_hitting_the_rate_limitbut_still/gstm1a9/

endeavor51 avatar Mar 30 '21 18:03 endeavor51

i'm still getting it.. any idea where to add the delay?

scottjl avatar Mar 30 '21 19:03 scottjl

I haven't had time to look at the code (never was very good with Python). I tried manipulating the cooldown feature unsuccessfully.

An maintained fork of Shreddit is available here: https://github.com/pythonInRelay/Shreddit But that fork doesn't have a fix for this yet either.

endeavor51 avatar Mar 30 '21 19:03 endeavor51

See here: https://github.com/pythonInRelay/Shreddit/issues/9

Add ratelimit_seconds=45 to your praw.ini within your username section. I also added to a [default] section at the top of my praw.ini. thx to @KenMacD

diversionmary avatar Mar 31 '21 17:03 diversionmary

And if you're like me, and ratelimit_seconds=45 didn't do anything, make sure your praw is up to date. pip3 install --upgrade praw and you should be g2g.

xb4r7x avatar Mar 31 '21 17:03 xb4r7x

rate_limit_seconds in praw.ini didn't help me.

I added a few

time.sleep(4) 

to shredder.py so that it sleeps for 4 seconds after each edit. That seems to have fixed it. It just takes a little longer now. (shredder.py is located in C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\Lib\site-packages\shreddit on windows)

benninkcorien avatar May 11 '21 13:05 benninkcorien

Did you make sure that praw was up to date? The rate_limit_seconds thing only works in more recent versions. Your work around works, but is kinda silly when the functionality is already baked in.

xb4r7x avatar May 11 '21 15:05 xb4r7x

I installed everything today, but didn't check the praw version in requirements.text - will see if I can update, thank you!

Edit - went from v5x to v7x ... I've already ran shreddit so can't test at the moment, but I'll assume setting the rate limit in praw.ini works better.

benninkcorien avatar May 11 '21 17:05 benninkcorien

I also ran into this problem today. praw version is up-to-date, rate_limit_seconds = 45 is set in praw.ini, but I can't still run it. it seems that adding time.sleep(4) works, but it is very slow.

EDIT: changed time.sleep(4) to time.sleep(2) to speed-up the process and it works just fine

phayzeeVW avatar Jun 10 '21 12:06 phayzeeVW

strange. the delay time must somehow be tied to the reddit account itself. other than adjusting mine from 31 to 45 i haven't made any other changes and it runs just fine. i run it once a night at 2am via cron. it sweeps up messages and posts.

scottjl avatar Jun 10 '21 12:06 scottjl