allow_redirects
Requestは(HEAD以外)デフォルトリダイレクトする
historyのプロパティでリダイレクトされたかの歴史を追跡できる
例
GitHub はHTTPをHTTPSにリダイレクトする
default
>>> r = requests.get('http://github.com/')
>>> r.url
'https://github.com/'
>>> r.status_code
200
>>> r.history
[<Response [301]>]
allow_redirects=Falseを設定すると、リダイレクトをしない
allow_directs=False
>>> r = requests.get('http://github.com/', allow_redirects=False)
>>> r.status_code
301
>>> r.history
[]
HEADの場合、デフォルトはリダイレクトしない
リダイレクトをしたい場合、allow_redirects=Trueを設定すれば
allow_directs=True
>>> r = requests.head('http://github.com/', allow_redirects=True)
>>> r.url
'https://github.com/'
>>> r.history
[<Response [301]>]
参考
