主页
Python
Python Requests head() 方法
demo_requests_head_timeout
运行 ❯
×
更改方向
保存代码
更改主题
import requests url = 'https://freew3c.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)
C:\Users\My Name>python demo_requests_head_timeout.py
Connection to w3schools.com timed out. (connect timeout=0.001)