Search code examples
pythonpraw

Flairing a post with PRAW


I'm working with PRAW, a Python Reddit API client. I'm trying to submit a post to a subreddit that requires flairs. This is my code so far:

subreddit = reddit.subreddit("test")
subreddit.submit(random.choice(p),selftext=random.choice(pc))

However, after trying to submit...

praw.exceptions.RedditAPIException: SUBMIT_VALIDATION_FLAIR_REQUIRED: 'Your post must contain post flair.' on field 'flair'

After adding a flair value:

subreddit.submit(random.choice(p),selftext=random.choice(pc),flair="other")
TypeError: submit() got an unexpected keyword argument 'flair'

How can I add a flair to my post? (only related post I could find is this outdated answer)


Solution

  • https://praw.readthedocs.io/en/latest/code_overview/models/subreddit.html#praw.models.Subreddit.submit

    Use either flair_id or flair_text depending on template's flair_text_editable value.