How to call a timeout error python code example
Example: python timeout exception
--------------------------------------------------------------
Timeout function
--------------------------------------------------------------
import asyncio
from async_timeout import timeout
class Student:
def __init__(self):
self.queue = asyncio.Queue()
pass
async def function(self):
try:
async with timeout(300):
pass
except asyncio.TimeoutError as e:
print(e)
--------------------------------------------------------------
Requests
--------------------------------------------------------------
import requests as r
class Student:
def __init__(self):
pass
def function(url:string):
try:
data = r.get(url, timeout=10.0)
except requests.Timeout as err:
logger.error({"message": err.message})
except Exception as err:
print(err)
return data