Skip to content

Instantly share code, notes, and snippets.

@kennethreitz
Forked from Miserlou/gist:1294412
Created October 18, 2011 03:54
Show Gist options
  • Save kennethreitz/1294570 to your computer and use it in GitHub Desktop.
Save kennethreitz/1294570 to your computer and use it in GitHub Desktop.
Posting JSON in Python without Requests Library
1 import urllib2
2 import json
221 def basic_authorization(user, password):
222 s = user + ":" + password
223 return "Basic " + s.encode("base64").rstrip()
224
225 def submit_pull_request(user, repo):
226 auth = (settings.username, settings.password)
227 url = 'https://api.github.com/repos/' + user + '/' + repo + '/pulls'
228 params = {'title': 'My Title', 'body': 'My Boday'}
239 req = urllib2.Request(url,
240 headers = {
241 "Authorization": basic_authorization(settings.username, settings.password),
242 "Content-Type": "application/json",
243 "Accept": "*/*",
244 "User-Agent": "Myapp/Gunio",
245 }, data = json.dumps(params))
246 f = urllib2.urlopen(req)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment