Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pycurl https error: unable to get local issuer certificate

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

like image 654
prongs Avatar asked Apr 24 '13 13:04

prongs


1 Answers

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()
like image 192
mata Avatar answered Oct 15 '22 18:10

mata