pycurl https error: unable to get local issuer certificate

prongs picture prongs · Apr 24, 2013 · Viewed 16.6k times · Source

Screenshot of the error

>>> import pycurl
>>> c = pycurl.Curl()
>>> c.setopt(c.URL, 'https://quora.com')
>>> c.perform()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pycurl.error: (60, 'SSL certificate problem: unable to get local issuer certificate')
>>>
>>> c.setopt(c.URL, 'http://quora.com')
>>> c.perform()
>>>
>>>

Why is it unable to get local issuer certificate? How do I solve this? When I open quora.com in my browser, I see that its identity is verified. Why is this the case? How do I get pycurl to use the same certificates my browser uses? enter image description here

Answer

mata picture mata · Apr 24, 2013

The problem is that pycurl needs an up-to-date certificate chain to verify the ssl certificates.

A good solution would be to use certifi.

It's basically an up-to-date copy of mozilla's built in certificate chain wrapped in a python package which can be kept up to date using pip. certifi.where() gives you the location to the certificate bundle.

To make pycurl to use it, set the CAINFO option:

import pycurl
import certifi

curl = pycurl.Curl()
curl.setopt(pycurl.CAINFO, certifi.where())
curl.setopt(pycurl.URL, 'https://www.quora.com')
curl.perform()