If you are using GET, OPTIONS, POST, PUT, PATCH or DELETE, then you can disable redirection processing via the allow_redirects parameter:
>>> r = requests.get('http://github.com', allow_redirects=False)
>>> r.status_code
301
>>> r.history []
You can use history
methods to track redirects
>>> r = requests.get('http://github.com')
>>> r.url
'https://github.com/'
>>> r.status_code 200 >>> r.history [<Response [301]>]
If you used the HEAD method, you can also enable redirection:
>>> r = requests.head('http://github.com', allow_redirects=True)
>>> r.url
'https://github.com/'
>>> r.history [<Response [301]>]