how to make https requests with python httplib2 ssl

Here are few snippets to make secure http requests using various python libraries.


import httplib2

link = "
h = httplib2.Http(".cache")
r, content = h.request(link, "GET")
another exmaple
import httplib2

h = httplib2.Http(".cache")
h.add_credentials('user', 'pass')
r, content = h.request("", "GET")

print r['status']
print r['content-type']


Here is a simmilar example using urlib2 for comparison and lines of code.

import urllib2

gh_url = ''

auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(None, gh_url, 'user', 'password')

opener = urllib2.build_opener(auth_handler)
handler = urllib2.urlopen(gh_url)

print handler.getcode()
print handler.headers.getheader('content-type')


The easiest, has always been requests.

import requests

r = requests.get('')
#r = requests.get('', auth=('user', 'pass'))
print r.status_code
print r.headers['content-type']

Hope this helps.

Varun Pant

how to make https requests with python httplib2 ssl  by  Varun Pant