From fb52a987db4a26bc087b6fbc0dba4dea584fdc1c Mon Sep 17 00:00:00 2001 From: ahmad-sheraz Date: Sun, 29 Dec 2024 18:50:20 -0500 Subject: [PATCH] Add example for handling timeouts in advanced.rst --- docs/user/advanced.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/user/advanced.rst b/docs/user/advanced.rst index ff3a3d0f26..6dc71509c8 100644 --- a/docs/user/advanced.rst +++ b/docs/user/advanced.rst @@ -1139,3 +1139,18 @@ coffee. .. _`wall clock`: https://wiki.php.net/rfc/max_execution_wall_time .. _`connect()`: https://linux.die.net/man/2/connect + +Handling Timeouts +----------------- + +You can specify a timeout for your request using the `timeout` parameter. If the request takes longer than the specified time, a `Timeout` exception will be raised: + +.. code-block:: python + + import requests + + try: + response = requests.get('https://api.github.com', timeout=5) + print(response.status_code) + except requests.Timeout: + print("The request timed out.") \ No newline at end of file