mellort/reddit_api — Issue #36: modhash solution
Author: jabbalaci
Created: 2011-11-10 11:38:37+00:00
State: open

Hi,

In `reddit.py`, it is written in comments at function `_fetch_modhash`:

*# TODO: find the right modhash url, this is only temporary*

I have the following solution:

r = reddit.Reddit(user_agent="my_cool_application")
r.login(user=USERNAME, password=PASSWORD)
opener = r._opener

def get_modhash():
url = 'http://www.reddit.com/api/me.json'
data = json.load(opener.open(url))
return data['data']['modhash'] if 'data' in data else False

print get_modhash()

It solves two things: the modhash is not in quotes (see my [previous ticket](https://github.com/mellort/reddit_api/issues/35)) and it is extractred from JSON, which is more elegant than doing regex on HTML source.

Laszlo