demo_requests_head_timeout.py:
import requests url = 'https://begtut.com/python/demopage.php' #to demonstrate the 'timeout' parameter, we set the timeout to 0.001 to guarantee that the connection will be timed out: x = requests.head(url, timeout=0.001) print(x.status_code)
➜ begtut>python demo_requests_head_timeout.py
Connection to begtut.com timed out. (connect timeout=0.001)