Ignoring SSL: CERTIFICATE_VERIFY_FAILED issue¶
There are a million and one SSL issues you can end up encountering on Python. Some of the most common scream about CERTIFICATE_VERIFY_FAILED
, or more specifically something like this:
1348 h.request(req.get_method(), req.selector, req.data, headers,
1349 encode_chunked=req.has_header('Transfer-encoding'))
1350 except OSError as err: # timeout error
-> 1351 raise URLError(err)
1352 r = h.getresponse()
1353 except:
URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:992)>
If we're using requests
, there are all sorts of ways to get around this. The easiest is to just add verify=False
to your requests.get()
call. This will ignore the SSL certificate and let us move on with your life.
If we're using pd.read_csv
to have pandas read a CSV from a remote server, though, it isn't that easy! You can't just add verify=False
to the call! Instead, we'll do this:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
df = pd.read_csv(...)
df.head()
And then we'll be able to read the CSV!
Normally the ssl
library uses _create_default_https_context
to create a nice secure https connection. In this case, though, the https connection won't work, so we're overwriting _create_default_https_context
with _create_unverified_context
, which will just ignore the SSL certificate.
It's not a great solution, but it's a solution!