demo_requests_post_allow_redirects.py:
import requests #to demonstrate the 'allow_redirects' parameter we use 'http' instead of 'https', begtut.com automatically redirects http requests to https: url = 'http://begtut.com/python/demopage.htm' myobj = {'somekey': 'somevalue'} #first, make a request without setting the 'allow_redirects' parameter to False: x = requests.post(url, data = myobj) print(x.text) print("----------------") #then, make a request with the 'allow_redirects' parameter set to False: x = requests.post(url, data = myobj, allow_redirects=False) print(x.text)
➜ begtut>python demo_requests_post_allow_redirects.py
<!DOCTYPE html>
<html>
<body>
<h1>This is a Test Page</h1>
</body>
</html>
----------------
<head><title>Document Moved</title></head>
<body><h1>Object Moved</h1>This document may be found <a HREF="https://www.begtut.com/python/demopoage.htm">here</a></body>