Skip to content

Instantly share code, notes, and snippets.

@cqfd
Created July 16, 2012 15:50
Show Gist options
  • Save cqfd/3123454 to your computer and use it in GitHub Desktop.
Save cqfd/3123454 to your computer and use it in GitHub Desktop.
POSTing to github's gist api
import json
import urllib
import urllib2
url = "https://api.github.com/gists"
data = {'description': 'gistin from a script',
'public': True,
'files': {
'foobarbaz.txt' : {'content': 'foo bar baz' }
}}
json_data = json.dumps(data)
req = urllib2.Request(url, json_data, {'Content-Type': 'application/json'})
res = urllib2.urlopen(req)
print res.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment