demo_requests_head_allow_redirects.py:
import requests url = 'https://begtut.com/python/demopage.php' x = requests.head(url) #Since the server will redirect this url to 'https://begtut.com/python/demopage.php' #AND the head method by default do not allow redirects, we will get an 301 status code. print(x.status_code)
➜ begtut>python demo_requests_head_allow_redirects.py
301