Skip to content

Instantly share code, notes, and snippets.

@pcote
Created August 28, 2012 18:19
Show Gist options
  • Save pcote/3501685 to your computer and use it in GitHub Desktop.
Save pcote/3501685 to your computer and use it in GitHub Desktop.
Sample for interacting with Reddit using Python 2.7
# reddit27_samp.py
# http://docs.python.org/release/2.5.2/lib/httplib-examples.html
import httplib
url_string = "www.reddit.com"
header_stuff = {"User-Agent":"blah blah blah"}
reddit_feed = "/r/skydiving.json"
conn = httplib.HTTPConnection(url_string)
conn.request(method="GET", url=reddit_feed, headers=header_stuff)
res = conn.getresponse()
data = res.read()
print(data)
# reddit27_samp.py
import httplib
url_string = "www.reddit.com"
header_stuff = {"User-Agent":"blah blah blah"}
reddit_feed = "/r/skydiving.json"
conn = httplib.HTTPConnection(url_string)
conn.request(method="GET", url=reddit_feed, headers=header_stuff)
res = conn.getresponse()
data = res.read()
print(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment