Implement aiohttp.client_exceptions.CertificateError and aiohttp.client_exceptions.SSLError #2294
Description
Long story short
My idea is implement 2 new exceptions aiohttp.client_exceptions.CertificateError and aiohttp.client_exceptions.SSLError which has bases ssl.CertificateError and ssl.SSLError as well aiohttp.client_exceptions.ClientOSError. When users catch aiohttp.client_exceptions.ClientOSError there is no way to understand is it ssl error, dns error or networking error or whatever else
There is a list of all exceptions and their bases in ssl module
<class 'ssl.CertificateError'> (<class 'ValueError'>,)
<class 'ssl.SSLEOFError'> (<class 'ssl.SSLError'>,)
<class 'ssl.SSLError'> (<class 'OSError'>,)
<class 'ssl.SSLSyscallError'> (<class 'ssl.SSLError'>,)
<class 'ssl.SSLWantReadError'> (<class 'ssl.SSLError'>,)
<class 'ssl.SSLWantWriteError'> (<class 'ssl.SSLError'>,)
<class 'ssl.SSLZeroReturnError'> (<class 'ssl.SSLError'>,)
Expected behaviour
aiohttp.client_exceptions.CertificateError: Cannot connect to host expired.badssl.com:443 ssl:True [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)]
Actual behaviour
will raise
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host expired.badssl.com:443 ssl:True [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)]
import aiohttp
import asyncio
async def main():
async with aiohttp.ClientSession() as session:
async with session.get('https://expired.badssl.com/') as response:
return await response.text()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())Your environment
Python 3.6.2
Mac OS X 10.12.6
latest aiohttp master branch