Skip to content

Instantly share code, notes, and snippets.

@jarhill0
Created February 12, 2020 21:28
Show Gist options
  • Save jarhill0/4b64ece572b2304f8073c2319ad445df to your computer and use it in GitHub Desktop.
Save jarhill0/4b64ece572b2304f8073c2319ad445df to your computer and use it in GitHub Desktop.
Checking for multiple exceptions.
import praw
SUB_NAME = "###"
# ^ This name should be a subreddit that only allows link posts and not
# self posts. Preferably you should mod it (but not with the account
# that you run this script as), because it is going to get spammed.
reddit = praw.Reddit() # fill in
subreddit = reddit.subreddit(SUB_NAME)
for x in range(50):
try:
subreddit.submit(str(x), url=f'https://duckduckgo.com/?q={x}')
except praw.exceptions.APIException as e:
assert e.error_type == 'RATELIMIT'
print(f'Successfully post rate-limited in {SUB_NAME}')
break
subreddit.submit('Hello World', selftext='') # throws APIException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment