For python urllib IOError and OSError should suffice. At least in py3.
import urllib.request try: urllib.request.urlopen('https://wrong.host.badssl.com/') except (IOError, OSError): pass
ssl.CertificateError: hostname 'wrong.host.badssl.com' doesn't match either of '*.badssl.com', 'badssl.com'
For python urllib IOError and OSError should suffice. At least in py3.