Hick
Hick

Reputation: 36414

404 error while doing an api call to Reddit

According to their documentation:

This should be enough to get the hottest new reddit submissions:

r = client.get(r'http://www.reddit.com/api/hot/', data=user_pass_dict)

But it doesn't and I get a 404 error. Am I getting the url for data request wrong?

http://www.reddit.com/api/login works though.

Upvotes: 1

Views: 869

Answers (2)

bboe
bboe

Reputation: 4412

Your question specifically asks what you need to do to get the "hottest new" submissions. "Hottest new" doesn't really make sense as there is the "hot" view and a "new" view. The URLs for those two views are http://www.reddit.com/hot and http://www.reddit.com/new respectively.

To make those URLs more code-friendly, you can append .json to the end of the URL (any reddit URL for that matter) to get a json-representation of the data. For instance, to get the list of "hot" submissions make a GET request to http://www.reddit.com/hot.json.


For completeness, in your example, you attempt to pass in data=user_pass_dict. That's definitely not going to work the way you expect it to. While logging in is not necessary for what you want to do, if you happen to have need for more complicated use of reddit's API using python, I strongly suggest using PRAW. With PRAW you can iterate over the "hot" submissions via:

import praw
r = praw.Reddit('<REPLACE WITH A UNIQUE USER AGENT>')
for submission in r.get_frontpage():
    # do something with the submission
    print(vars(submission))

Upvotes: 1

George Cummins
George Cummins

Reputation: 28926

According to the docs, use /hot rather than /api/hot:

r = client.get(r'http://www.reddit.com/hot/', data=user_pass_dict)

Upvotes: 0

Related Questions