如果你使用的是GET、OPTIONS、POST、PUT、PATCH 或者 DELETE,那么你可以通过 allow_redirects 参数禁用重定向处理:

>>> r = requests.get('http://github.com', allow_redirects=False)
>>> r.status_code
301
>>> r.history [] 

可以使用history方法来追踪重定向

>>> r = requests.get('http://github.com')

>>> r.url
'https://github.com/'

>>> r.status_code 200 >>> r.history [<Response [301]>] 

如果你使用了 HEAD 方法,你也可以启用重定向:

>>> r = requests.head('http://github.com', allow_redirects=True)
>>> r.url
'https://github.com/'
>>> r.history [<Response [301]>]