praw-dev / praw

PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.
http://praw.readthedocs.io/
BSD 2-Clause "Simplified" License
3.47k stars 456 forks source link

Unable to get flairs in a subreddit #1948

Closed pnpninja closed 1 year ago

pnpninja commented 1 year ago

Describe the Bug

hi everyone m trying to run this code but it returns the error

for flair in reddit.subreddit("minefortest").flair(limit=None):
   print(flair)

Getting - prawcore.exceptions.Forbidden: received 403 HTTP response

(not a auth error)

Desired Result

### Code to reproduce the bug ```Python for flair in reddit.subreddit("minefortest").flair(limit=None): print(flair) ``` ### The `Reddit()` initialization in my code example does not include the following parameters to prevent credential leakage: `client_secret`, `password`, or `refresh_token`. - [X] Yes ### Relevant Logs ```Shell None ``` ### This code has previously worked as intended. Yes ### Operating System/Environment macOS Monterey 12.5.1 ### Python Version 3.7.16 ### PRAW Version 7.7.0 ### Prawcore Version 2.3.0 ### Anything else? _No response_
Watchful1 commented 1 year ago

A 403 error means you do not have access. Either the account does not have flair permissions on the subreddit or you are not logged in properly.

LilSpazJoekp commented 1 year ago

Closed as this isn't an issue/bug with PRAW.

milahu commented 1 month ago

in my case, this error was fixed by using subreddit.flair.link_templates instead of subreddit.flair.templates

which is confusing, because the link_templates flairs also work with text posts, not just with link posts

praw-subreddit-get-flairs.py ```py #!/usr/bin/env python3 import sys import traceback import praw # python reddit api wrapper # my_secrets.py from my_secrets import ( reddit_client_id, reddit_client_secret, reddit_user_agent, reddit_username, reddit_password, ) subreddit_name_list = [ "test", "DHExchange", ] reddit = praw.Reddit( client_id=reddit_client_id, client_secret=reddit_client_secret, user_agent=reddit_user_agent, username=reddit_username, password=reddit_password, ) for subreddit_name in subreddit_name_list: print() print("subreddit_name", subreddit_name) subreddit = reddit.subreddit(subreddit_name) print("subreddit.flair.templates") try: for template in subreddit.flair.templates: print("template", template["id"], repr(template["text"])) except Exception as exc: traceback.print_exception(exc, limit=0, chain=False) print("subreddit.flair.link_templates") try: for template in subreddit.flair.link_templates: print("template", template["id"], repr(template["text"])) except Exception as exc: traceback.print_exception(exc, limit=0, chain=False) print("subreddit.flair") try: for flair in subreddit.flair(): print("flair", flair) except Exception as exc: traceback.print_exception(exc, limit=0, chain=False) ```
output ``` subreddit_name test subreddit.flair.templates template 6d823ab2-be2f-11e8-9779-0e18b5e69680 '' subreddit.flair.link_templates template 6b39b4a6-be2f-11e8-ac14-0e2593696d0a '' subreddit.flair prawcore.exceptions.Forbidden: received 403 HTTP response subreddit_name DHExchange subreddit.flair.templates prawcore.exceptions.Forbidden: received 403 HTTP response subreddit.flair.link_templates template bfb2a99a-8a91-11ea-8e13-0e8ed90babe5 'Request' template 07baffd6-e6ed-11eb-af31-0eab196cd081 'Sharing' template 0cbea460-e6ed-11eb-8a0b-0ea4ce18312f 'Meta' subreddit.flair prawcore.exceptions.Forbidden: received 403 HTTP response ```