Take a case in which we are trying to access a response which is taking too much time. If we don't want to get the process moving forward and give out an exception if it exceeds a specific amount of time, we can use the parameter timeout
.
When we use the timeout
parameter, we are telling Requests not to wait for a response after some specific time period. If we use timeout
, it's not equivalent to defining a time limit on the whole response download. It's a good practice to raise an exception if no bytes have been acknowledged on the underlying socket for the stated timeout
in seconds.
>>> requests.get('http://google.com', timeout=0.03) --------------------------------------------------------------------------- Timeout Traceback (most recent call last) ……. …….. Timeout: HTTPConnectionPool(host='google.com', port=80): Read timed out. (read timeout=0.03)
In this example we have specified the timeout
value as 0.03
in which the timeout has been exceeded to bring us the response and so it resulted us the timeout
exception. The timeout may occur in two different cases:
3.133.128.145