praw-dev / praw

PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

Home Page:http://praw.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Subreddits whose flairs are "Not available for this community" return 403

ElliotKillick opened this issue · comments

Describe the Bug

r/software has flairs configured as unavailable: https://www.reddit.com/r/software/submit

Trying to enumerate flairs with PRAW under this condition causes a 403. I can grab the flairs for other subreddits just fine so this does appear to be the root cause.

Desired Result

Cleanly return an empty generator. No exception raised.

Code to reproduce the bug

import praw

# Authenticate...
reddit = praw.Reddit(...)

subreddit = reddit.subreddit("software")
flairs = subreddit.flair.link_templates.user_selectable()
print(list(flairs)) # Server returns 403!

The Reddit() initialization in my code example does not include the following parameters to prevent credential leakage:

client_secret, password, or refresh_token.

  • Yes

Relevant Logs

File "/home/user/.local/lib/python3.11/site-packages/prawcore/sessions.py", line 266, in _request_with_retries
    raise self.STATUS_EXCEPTIONS[response.status_code](response)
prawcore.exceptions.Forbidden: received 403 HTTP response

This code has previously worked as intended.

No

Operating System/Environment

GNU/Linux

Python Version

3.11.4

PRAW Version

7.7.1

Prawcore Version

2.3.0

Anything else?

Thank you for making PRAW, it's a great piece of software!

This is likely something we will not support. An empty list is different from not enabled. An empty list means that the subreddit has none while 403 means it is explicitly disabled.

I'm not sure the specifics of the API and so forth. However, returning empty or None is often preferable to raising exceptions (especially when their meaning is ambiguous because a 403 could, for example, also mean the subreddit is private).

I also found that it violates POLS/POLA

PRAW rarely catches exceptions for the end user. The only instances I can think of when stickying, partial_redditors, and submitting media. In all of these instances PRAW does something in response to the exception. As such, this should be handled in the user's code. In this instance a 403 has a meaning: you're not allowed to get the user selectable flairs. I think the reason why Reddit raises a 403 instead of returning an empty list is because a subreddit can still have user selectable flairs populated but has the option to actually allow the user to select them disabled. I understand it is preferable to not raise an exception, but the exception is originating from the API and not PRAW.

I also found that it violates POLS/POLA

This is an issue with Reddit's API. Their API has many surprises and PRAW tries its best to handle these for you but at times this is futile.