-
-
Save kennethreitz/1294570 to your computer and use it in GitHub Desktop.
Posting JSON in Python without Requests Library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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