Skip to content

Instantly share code, notes, and snippets.

@grodtron
Created August 25, 2011 17:42
Show Gist options
  • Save grodtron/1171258 to your computer and use it in GitHub Desktop.
Save grodtron/1171258 to your computer and use it in GitHub Desktop.
A gist to test the Gist API
#!/usr/bin/python
import urllib2
import base64
import json
filename = __file__.split("/")[-1]
data = {}
data["description"] = "A gist to test the Gist API"
data["public"] = True
data["files"] = {filename:{}}
data["files"][filename]["content"] = open(__file__).read().replace("******", "******")
url = "https://api.github.com/gists"
auth_string = "grodtron:******"
auth_string = base64.encodestring(auth_string)[:-1]
req = urllib2.Request(url, json.dumps(data))
req.add_header("Authorization", "Basic %s" % auth_string)
try:
result = urllib2.urlopen(req)
print result.read()
except urllib2.URLError, e:
print e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment