I'm trying to do some basic HTTP authentication with the Reddit API using my username as a test, but I still get 429 errors (too many requests) occasionally when I'm nowhere near the limit. I was partially following this guide: How To use reddit API in python I'm not sure what I did, but I'm getting a syntax error with the print command at the end of the code now, which is written the same as in the guide. Here's my code:
CLIENT_ID = "<CLIENT_ID>"
CLIENT_SECRET = "<CLIENT_SECRET>"
REDIRECT_URL = "http://localhost:65010/reddit_callback"
import pprint
import json
import requests
import requests.auth
headers = {'user-agent': 'Test Script by /u/<USERNAME>'}
client_auth = requests.auth.HTTPBasicAuth(CLIENT_ID, CLIENT_SECRET)
post_data = {"grant_type": "password",
"username": "<USERNAME>", "password": "<PASSWORD>"}
response = requests.post("https://ssl.reddit.com/api/v1/access_token",
auth=client_auth, data=post_data)
client = requests.session()
client.headers = headers
r = client.get(r'http://www.reddit.com/user/<USERNAME>/about/.json')
r.text
data = r.json()
print data['data']['children'][0]
Sorry, I know I'm probably doing really stupid things, thanks in advance for your help in sorting me out! Oh, also, this is Python-3.4 on Ubuntu 14.04 LTS with the latest version of Requests for Python.