Monday 15 August 2011

python - 404 error when requesting json in Reddit API -


I am trying to log in to reddit and am getting my account data.

Import it to import the import of import from my Python Code:

  json username = 'dirk_b' password = 'willnottell' user_pass_dict = {'user' Header = {'dirkie': '/ u / dirk_b API Python Test',} client = requests.session () client: username, passwd ': password,' api_type ':' json ',' rem ': true,} Headers = headers R = client.post (r'http: //www.reddit.com/api/login ', data = user_pass_dict) j = json.loads (r.content.decode ()); Client.modhash = j ['json'] ['data'] ['modhash'] s = client.post (r'http: //www.reddit.com/api/me.json ', data = user_pass_dict) Impressions (S content)   

The response I get is: b '{"error": 404}'

If I request the same without the .json part I do I get a group of HTML code with 'reddit.com: page not found', so I think I am doing something wrong with the URL. But the more I use this URL, the same is specified in the Reddit API.

The reason I am not using PRAW, because I want to be able to eventually do it in C ++, but I wanted to make sure that it works first in Python.

receives only the request:

  s = client.get ('Http://www.reddit.com/api/me.json')   

There is no post route to that end point, so you will get 404 for it.

In addition, if you need to pass modhash on the server, do so in the data provided in the postal request; Settings client.modhash does no then pass that parameter to the server retrieve Em> modhash:

  r = client.get ('http: //www.reddit .com / api / me.json') modhash = r.json () ['modhash']   

Note that a response from request . There is no need to use the Json () method, the json module itself.

Then you should use the modhash in POST request data:

  client.post ('http://www.reddit.com/ Api / updateapp ', {' modhash ': modhash,' about_url ':' ... ', ...})    

No comments:

Post a Comment