Explained about to setup not to follow 302 / 301 redirects in different python modules

Requests

import requests
r = requests.get('http://lesscoder.com', allow_redirects=False)
print(r.status_code)

httplib2

import httplib2
h = httplib2.Http()
h.follow_redirects = False
(response, body) = h.request("http://example.com")

urllib2

class NoRedirect(urllib2.HTTPRedirectHandler):
    def redirect_request(self, req, fp, code, msg, hdrs, newurl):
        pass

noredir_opener = urllib2.build_opener(NoRedirect())
urllib2.install_opener(noredir_opener)
print urllib2.urlopen(url).read()

curl

curl -v http://lesscoder.com

To follow redirect add -L

curl -v -L http://lesscoder.com