I have the following code to check url status code:
async def _is_url_ok(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
return resp.status == 200
What is the best way to handle an exception? Is it ok to do like this?
async def _is_url_ok(url):
try:
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
return resp.status == 200
except:
return False
It depends on what is your target.
Sometimes you need a page content validation etc.
Anyway catching aiohttp.ClientError
is better than bare except
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With