reddit-twitter-bot icon indicating copy to clipboard operation
reddit-twitter-bot copied to clipboard

`KeyError` in `praw.Reddit`

Open SylvainDe opened this issue 8 years ago • 4 comments

After a system upgrade, I've created a new virtual env, installed Praw in it and tried to run the script and got this exact issue:

http://stackoverflow.com/questions/36361826/keyerror-when-assigning-praw-reddit-to-variable

I guess that the API of Praw has changed. I open this issue to share my findings/progress (if any).

SylvainDe avatar Dec 30 '16 17:12 SylvainDe

A few other APIs have changed ("get" prefix are removed everywhere). I had to perform the following changes to make things work:

-    reddit_api = praw.Reddit('reddit Twitter tool monitoring {}'.format(subreddit))
-    subreddit = reddit_api.get_subreddit(subreddit)
-    return subreddit
+    reddit_api = praw.Reddit(
+            user_agent='reddit Twitter tool monitoring {}'.format(subreddit_name),
+            client_id='xxxxxxxxx',
+            client_secret='yyyyyyyyyyyyyy')
+    return reddit_api.subreddit(subreddit_name)

and

-    for submission in subreddit_info.get_hot(limit=5):
+    for submission in subreddit_info.hot(limit=5):

Also, the link used did not seem correct but this might be specific to the code I had locally.

SylvainDe avatar Dec 30 '16 18:12 SylvainDe

Also, the permalink attribute on submission is now a relative link so: 1) the link will not work 2) the link will not be detected by Twitter as a link, will not be substituted by a (usually shorter) link and the tweet is likely to be more than 140 char longs...

SylvainDe avatar Jan 02 '17 14:01 SylvainDe

I ran into this same problem, does the issue with relative links apply to external links (imgur for example)?

corbindavenport avatar Jan 03 '17 20:01 corbindavenport

I guess it only applies to reddit links...

SylvainDe avatar Jan 03 '17 21:01 SylvainDe