Skip to content

Instantly share code, notes, and snippets.

@Miserlou
Created October 18, 2011 01:41
Embed
What would you like to do?
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