title: Reddit API Authentication using Requests for Python
body: <p>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: <a href="http://www.pythonforbeginners.com/api/how-to-use-reddit-api-in-python" rel="nofollow">How To use reddit API in python</a>
  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:</p>
  
  <pre><code>CLIENT_ID = "&lt;CLIENT_ID&gt;"
  CLIENT_SECRET = "&lt;CLIENT_SECRET&gt;"
  REDIRECT_URL = "http://localhost:65010/reddit_callback"
  
  import pprint
  import json
  import requests
  import requests.auth
  
  headers = {'user-agent': 'Test Script by /u/&lt;USERNAME&gt;'}
  
  client_auth = requests.auth.HTTPBasicAuth(CLIENT_ID, CLIENT_SECRET)
  
  post_data = {"grant_type": "password", 
               "username": "&lt;USERNAME&gt;", "password": "&lt;PASSWORD&gt;"}
  
  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/&lt;USERNAME&gt;/about/.json')
  r.text
  data = r.json()
  
  print data['data']['children'][0]
  </code></pre>
  
  <p>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.</p>