1 回答
TA贡献1765条经验 获得超5个赞
async def fetch(session, url):
"""[Coroutine to send HTTP request to URLs provided]
Args:
session ([aiohttp Client Session object]): [session object]
url ([string]): [URL to query]
Returns:
[list]: [response url, status and time taken]
"""
tic = time.perf_counter() # Start timer
try:
response = await session.request(method='GET', url=url, timeout=10)
toc = time.perf_counter() # Stop timer
time_taken = toc - tic # Calculate time taken to get response
response.raise_for_status()
print("URL : ", url)
print("HTTP Status : ", response.status)
print(f"Time taken : {time_taken:4f} seconds")
print()
return str(response.url), response.status, time_taken
except HTTPError as http_err:
logging.error(http_err)
except Exception as err:
logging.error(err)
添加回答
举报