0
votes

I'm using PRAW to work with reddit submissions, specifically submissions that have been resolved and have their "flair" attribute set to SOLVED (as described here).

However, I am getting "None" when I check for flair, even for submissions that I can see have been set to SOLVED.

I have the following code, which works with a submission that has definitely been set to SOLVED.

solvedSubmission = reddit.submission(url='https://www.reddit.com/r/PhotoshopRequest/comments/6ctkpj/specific_can_someone_please_remove_kids_12467_i/')
pprint.pprint(vars(solvedSubmission))

This outputs:

{'_comments_by_id': {},  
'_fetched': False,
'_flair': None,
'_info_params': {}, 
'_mod': None, 
'_reddit': <praw.reddit.Reddit object at 0x10e3ae1d0>, 
'comment_limit': 2048, 
'comment_sort': 'best', 
'id': '6ctkpj'}

Can anyone offer any insight as to why I'm seeing "None", on this post and other solved posts? Is there another way that reddit keeps track of solved posts that I should look into?

Thank you!

1
You're sure the reddit instance is valid? - Lincoln Bergeson
It should be. I'm calling it using my client_id, client_secret, user_agent, username, and password. However, I don't think I'm "fetching" the data correctly. When I try getting the subreddit with additional parameter "fetch=True", I get errors such as "Reddit object has no attribute 'get_subreddit'", or "__call__() got an unexpected keyword argument 'fetch'" praw.readthedocs.io/en/v3.6.0/pages/… - vchen

1 Answers

4
votes

By now (~1y after OP) you might have solved this already, but it came up in a search I did, and since I figured out the answer, I will share.

The reason you never saw any relevant information is because PRAW uses lazy objects so that network requests to Reddit’s API are only issued when information is needed. You need to make it non-lazy in order to retrieve all of the available data. Below is a minimal working example:

import praw
import pprint

reddit = praw.Reddit() # potentially needs configuring, see docs
solved_url = 'https://www.reddit.com/r/PhotoshopRequest/comments/6ctkpj/specific_can_someone_please_remove_kids_12467_i/'

post = reddit.submission(url=solved_url)
print(post.title) # this will fetch the lazy submission-object...
pprint.pprint(vars(solvedSubmission)) # ... allowing you to list all available fields

In the pprint-output, you will discover, as of the time of writing this answer (Mar 2018), the following field:

...
'link_flair_text': 'SOLVED',
...

... which is what you will want to use in your code, e.g. like this:

is_solved = 'solved' == post.link_flair_text.strip().lower()

So, to wrap this up, you need to make PRAW issue a network request to fetch the submission object, to turn it from a lazy into a full instance; you can do this either by printing, assigning to a variable, or by going the direct route into the object by using the field-name you want.